From c34d47ccd06d1858266e3e4c309e824bcc1f79b7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Sep 2009 23:49:42 +0100 Subject: [PATCH] Actually commit the capacity string parser --- yarrg/web/check_capacitystring | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 yarrg/web/check_capacitystring diff --git a/yarrg/web/check_capacitystring b/yarrg/web/check_capacitystring new file mode 100644 index 0000000..088c6c5 --- /dev/null +++ b/yarrg/web/check_capacitystring @@ -0,0 +1,88 @@ +<%doc> + + This is part of the YARRG website. YARRG is a tool and website + for assisting players of Yohoho Puzzle Pirates. + + Copyright (C) 2009 Ian Jackson + Copyright (C) 2009 Clare Boothby + + YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later). + The YARRG website is covered by the GNU Affero GPL v3 or later, which + basically means that every installation of the website will let you + download the source. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + are used without permission. This program is not endorsed or + sponsored by Three Rings. + + + This Mason component simply defines how to interpret capacities. + + + +<%attr> + + +<%method preparse> +<%args> +$h + +<%perl> + +my $def= sub { + my ($what,$val) = @_; + if (defined $h->{$what}) { + $h->{Emsg}= "Multiple definitions of maximum $what."; + } + print STDERR "SET $what $val\n"; + $h->{$what}= $val; +}; + +foreach $_ (split /\s+/, ${ $h->{String} }) { + print STDERR "ITEM \`$_'\n"; + next unless length; + if (m/^([1-9]\d{0,8})l$/) { + $def->('volume', $1); + } elsif (m/^([1-9]\d{0,8})kg$/) { + $def->('mass', $1); + } elsif (m/^([1-9]\d{0,5}(?:\.\d{0,3})?)kl/) { + $def->('volume', $1 * 1000); + } elsif (m/^([1-9]\d{0,5}(?:\.\d{0,3})?)t/) { + $def->('mass', $1 * 1000); + } else { + $h->{Emsg}= "Cannot understand capacity \`$_'."; + last; + } +} + + + +<%method postquery> +<%args> +$h + +<%perl> + +if (defined $h->{'mass'} or defined $h->{'volume'}) { + @{ $h->{Results} } = [ $h->{'mass'}, $h->{'volume'} ]; + + ${ $h->{Canon} }= + 'mass limit: '.(defined $h->{'mass'} ? $h->{'mass'} .'kg' : 'none').'; '. + 'volume limit: '.(defined $h->{'volume'} ? $h->{'volume'} .'l' : 'none').'.'; +} + + + -- 2.30.2