]> git.decadent.org.uk Git - memories.git/blobdiff - Tagtools.pm
I *think* this fixes #18.
[memories.git] / Tagtools.pm
index 0fc2529b370505206b4bc99f3aed29aae1c49b09..f161c475b4e9bcf9edd4090cfe1ffbfd697d0078 100644 (file)
@@ -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