diff options
author | Yorhel <git@yorhel.nl> | 2010-11-21 16:15:26 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-11-21 16:15:26 +0100 |
commit | a79312bb341bdfbdf14e7aeb3d1ffa6548604960 (patch) | |
tree | 9a5830431a5a980295f84d2901306e87f28ece12 /lib/VNDB/Func.pm | |
parent | 66e8cbc808775356ea5beeea2f53ab6958ab6c2e (diff) |
Implemented the server side of the new release filter selector
There's no validation of the filter string yet, and somehow I don't feel
like adding that; it's a lot of code and there's nothing to protect -
the values are inserted using parameters into a SELECT query, the worst
thing that could happen is the user receiving a 500.
Also, I've started using the perl '//=' operator, which was added in
5.10. This removes support for older perls.
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index f3f9d009..a693e1de 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -7,7 +7,13 @@ use YAWF ':html'; use Exporter 'import'; use POSIX 'strftime', 'ceil', 'floor'; use VNDBUtil; -our @EXPORT = (@VNDBUtil::EXPORT, qw| liststat clearfloat cssicon tagscore mt minage |); +our @EXPORT = (@VNDBUtil::EXPORT, qw| liststat clearfloat cssicon tagscore mt minage fil_parse fil_serialize |); + + +# three ways to represent the same information +our $fil_escape = '_ !"#$%&\'()*+,-./:;<=>?@[\]^`{}~'; +our @fil_escape = split //, $fil_escape; +our %fil_escape = map +($fil_escape[$_], $_), 0..$#fil_escape; # Argument: hashref with rstat and vstat @@ -89,5 +95,25 @@ sub minage { } +sub fil_parse { + return { map { + my($f, $v) = split /-/, $_, 2; + my @v = split /,/, $v; + s/_([0-9]{2})/$1 > $#fil_escape ? '' : $fil_escape[$1]/eg for(@v); + $f => @v > 1 ? \@v : @v + } split /\./, scalar shift }; +} + + +sub fil_serialize { + my $fil = shift; + my $e = qr/([\Q$fil_escape\E])/; + return join '.', map { + my @v = ref $fil->{$_} ? @{$fil->{$_}} : ($fil->{$_}); + s/$e/_$fil_escape{$1}/g for(@v); + $_.'-'.join ',', @v + } keys %$fil; +} + 1; |