5 use Storable qw(freeze); use MIME::Base64;
10 my %cache_options = ( 'namespace' => $whence.'TagTools',
11 'default_expires_in' => 600 );
13 new Cache::FileCache( \%cache_options ) or
14 croak( "Couldn't instantiate FileCache" );
15 *{$whence."::zap_cache"} = sub { $cache->Clear };
16 *{$whence."::do_cached"} = sub {
17 my ($self, $codeblock,$arg) = @_;
18 my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); }
19 my $c = $cache->get(0+$codeblock); return @$c if $c;
20 my @stuff = $codeblock->($arg);
21 $cache->set(0+$codeblock, [ @stuff ]);
24 *{$whence."::_tagcloud"} = sub {
25 my $cloud = HTML::TagCloud->new();
26 my $base = $whence->config->uri_base."tag/view/";
27 for my $tagging (($whence."::Tagging")->search_summary) {
28 my $name = $tagging->tag->name;
29 $cloud->add($name, $base.uri_escape($name), $tagging->{count})
33 *{$whence."::_calendar"} = sub {
36 my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd);
37 my @m = Calendar::Simple::calendar($m, $y);
39 foreach my $week (@m) {
41 foreach my $day (@$week) {
42 my $d = { day => $day };
44 my $tag = "date:$y-$m-".sprintf("%02d", $day);
45 my ($x) = ($whence."::SystemTag")->search(name => $tag);
46 if ($x) { $d->{tag} = "/system_tag/view/$tag" }
50 push(@month, \@weekdays);
54 for my $thing (qw(tagcloud calendar)) {
55 *{$whence."::$thing"} = sub { shift->do_cached($thing, @_) }
64 sub Time::Piece::next_month {
66 my $month = $tp + ONE_MONTH;
67 return if $month > Time::Piece->new;
70 sub Time::Piece::prev_month {
72 my $month = $tp - ONE_MONTH;