6 use Storable qw(freeze); use MIME::Base64;
8 use Text::Balanced qw(extract_multiple extract_quotelike);
12 my %cache_options = ( 'namespace' => $whence.'TagTools',
13 'default_expires_in' => 600 );
15 new Cache::FileCache( \%cache_options ) or
16 croak( "Couldn't instantiate FileCache" );
17 *{$whence."::zap_cache"} = sub { $cache->Clear };
18 *{$whence."::do_cached"} = sub {
19 my ($self, $codeblock,$arg) = @_;
20 my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); }
21 my $c = $cache->get($key); return @$c if $c;
22 my @stuff = $codeblock->($arg);
23 $cache->set($key, [ @stuff ]);
26 *{$whence."::_tagcloud"} = sub {
27 my $cloud = HTML::TagCloud->new();
28 my $base = $whence->config->uri_base."tag/view/";
29 for my $tagging (($whence."::Tagging")->search_summary) {
30 my $name = $tagging->tag->name;
31 $cloud->add($name, $base.uri_escape($name), $tagging->{count})
35 *{$whence."::_calendar"} = sub {
37 my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd);
38 my @m = Calendar::Simple::calendar($m, $y);
40 foreach my $week (@m) {
42 foreach my $day (@$week) {
43 my $d = { day => $day };
45 my $tag = "date:$y-$m-".sprintf("%02d", $day);
46 my ($x) = ($whence."::SystemTag")->search(name => $tag);
47 if ($x) { $d->{tag} = "/system_tag/view/$tag" }
51 push(@month, \@weekdays);
55 for my $thing (qw(tagcloud calendar)) {
56 *{$whence."::$thing"} = sub { shift->do_cached(\&{$whence."::_".$thing}, @_) }
73 sub Time::Piece::next_month {
75 my $month = $tp + ONE_MONTH;
76 return if $month > Time::Piece->new;
79 sub Time::Piece::prev_month {
81 my $month = $tp - ONE_MONTH;