X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Tagtools.pm;h=f161c475b4e9bcf9edd4090cfe1ffbfd697d0078;hb=2525a85fd1ecdd92d525e9667fc04a2afb75aec1;hp=0fc2529b370505206b4bc99f3aed29aae1c49b09;hpb=b9d021d4af1018ac2c60640678c1b790251190e9;p=memories.git diff --git a/Tagtools.pm b/Tagtools.pm index 0fc2529..f161c47 100644 --- a/Tagtools.pm +++ b/Tagtools.pm @@ -1,9 +1,11 @@ package Tagtools; +use URI::Escape; use HTML::TagCloud; use Carp; use Cache::FileCache; use Storable qw(freeze); use MIME::Base64; use Calendar::Simple; +use Text::Balanced qw(extract_multiple extract_quotelike); sub import { my $whence = caller; my ($class) = @_; @@ -16,9 +18,9 @@ sub import { *{$whence."::do_cached"} = sub { my ($self, $codeblock,$arg) = @_; my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); } - my $c = $cache->get(0+$codeblock); return @$c if $c; + my $c = $cache->get($key); return @$c if $c; my @stuff = $codeblock->($arg); - $cache->set(0+$codeblock, [ @stuff ]); + $cache->set($key, [ @stuff ]); return @stuff; }; *{$whence."::_tagcloud"} = sub { @@ -31,7 +33,6 @@ sub import { $cloud }; *{$whence."::_calendar"} = sub { - my $self = shift; my $arg = shift; my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd); my @m = Calendar::Simple::calendar($m, $y); @@ -52,11 +53,19 @@ sub import { return \@month; }; for my $thing (qw(tagcloud calendar)) { - *{$whence."::$thing"} = sub { shift->do_cached($thing, @_) } + *{$whence."::$thing"} = sub { shift->do_cached(\&{$whence."::_".$thing}, @_) } } } +sub separate_tags { + map { s/^"|"$//g; $_} + extract_multiple( + lc $_[1], [ + \&extract_quotelike, + qr/([^\s,]+)/ + ], undef,1) +} # THIS IS A HACK