]> git.decadent.org.uk Git - memories.git/blobdiff - Tagtools.pm
Rather more lightweight (and functional) tag completion code.
[memories.git] / Tagtools.pm
index 292e6e517a33c821e5f53bffd6efa2e3faea6a71..f161c475b4e9bcf9edd4090cfe1ffbfd697d0078 100644 (file)
@@ -1,4 +1,5 @@
 package Tagtools;
+use URI::Escape;
 use HTML::TagCloud;
 use Carp;
 use Cache::FileCache;
@@ -17,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 {
@@ -32,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);
@@ -53,7 +53,7 @@ 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}, @_) }
     }
 
 }