sponsored by Three Rings.
- This Mason component parses textual strings giving lists of islands
- and archipelagoes, ie textual route strings.
+ This Mason component simply defines how to look up route entries.
+ It is called by qtextstring.
</%doc>
-<%flags>
-inherit => 'qtextstringcheck'
-</%flags>
-
-<%args>
-$ocean
-$format
-$ctype => undef
-$string
-$returnhash => { }
-</%args>
-
-<%perl>
-
-# typical url for this script:
-# http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/routetextstring?format=json&ocean=Midnight&string=d
-
-use CommodsWeb;
-
-my $dbh= dbw_connect($ocean);
-
-my $sth= $dbh->prepare("SELECT archipelago,islandid,islandname
- FROM islands WHERE islandname LIKE ?
- UNION ALL SELECT DISTINCT archipelago,NULL,archipelago
- FROM islands WHERE archipelago LIKE ?");
-
-my $emsg= '';
-my (@results, $canontext);
-
-foreach my $each (split m#[/|,]#, $string) {
- $each =~ s/^\s*//; $each =~ s/\s*$//; $each =~ s/\s+/ /g;
- next if !length $each;
- my $err= sub { $emsg= sprintf $_[0], $each; last; };
- my %m;
- my $results;
- foreach my $pat ("$each\%", "\%$each\%") {
- $sth->execute($pat,$pat);
- $results= $sth->fetchall_arrayref();
- last if @$results==1;
- map { $m{ $_->[2] }=1 } @$results;
- $results= undef;
- }
- if (!$results) {
- if (!%m) {
- $err->('no island or arch matches "%s"');
- } elsif (keys(%m) > 5) {
- $err->(' ');
- } else {
- $err->('ambiguous island or arch "%s",'.
- ' could be '.join(', ', sort keys %m));
- }
- }
- push @results, $results->[0];
-};
-
-$dbh->rollback();
-
-return $emsg,
- (join ' | ', map { $_->[2] } @results),
- [ @results ];
-
-</%perl>
+<%attr>
+multiple => 1
+maxambig => 5
+</%attr>
+
+<%method sqlstmt>
+ SELECT islandname,islandid,archipelago
+ FROM islands WHERE islandname LIKE ?
+UNION ALL SELECT DISTINCT archipelago,NULL,archipelago
+ FROM islands WHERE archipelago LIKE ?
+</%method>
+
+<%method nomatch>
+ no island or arch matches "<% $ARGS{spec} |h %>"
+</%method>
+
+<%method ambiguous>
+ ambiguous island or arch "<% $ARGS{spec} |h %>",
+ could be <% $ARGS{couldbe} |h %>
+</%method>
+
+<%method manyambig>
+
+</%method>