From: Simon Cozens Date: Mon, 12 Feb 2007 20:38:44 +0000 (+0000) Subject: Shift things into Tagtools, to tidy up. X-Git-Tag: 1.2+svn20070808~42 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=7767c51977a235b2f9205da1a94b07ba55ad2f52;p=memories.git Shift things into Tagtools, to tidy up. git-svn-id: http://svn.simon-cozens.org/memories/trunk@26 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- diff --git a/Memories.pm b/Memories.pm index efad269..0aebf11 100644 --- a/Memories.pm +++ b/Memories.pm @@ -15,6 +15,7 @@ use Memories::Album; use URI::Escape; use Calendar::Simple; use XML::RSS; +use Tagtools; Memories->config->auth->{ user_field } = "name"; Memories->config->model("Maypole::Model::CDBI::Plain"); @@ -93,25 +94,6 @@ sub authenticate { return OK; } - -use Cache::SharedMemoryCache; -my %cache_options = ( 'namespace' => 'MemoriesStuff', - 'default_expires_in' => 600 ); -my $cache = - new Cache::SharedMemoryCache( \%cache_options ) or - croak( "Couldn't instantiate SharedMemoryCache" ); - -sub zap_cache { $cache->Clear } -use Storable qw(freeze); use MIME::Base64; -sub do_cached { - 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 @stuff = $codeblock->($arg); - $cache->set(0+$codeblock, [ @stuff ]); - return @stuff; -} - for my $how (qw(random recent interesting popular)) { no strict; my $method = "search_$how"; @@ -119,61 +101,6 @@ for my $how (qw(random recent interesting popular)) { *{$how} = sub { shift->do_cached(\&{"_$how"})}; } -sub tagcloud { shift->do_cached(\&_tagcloud) } - -sub _tagcloud { - my $cloud = HTML::TagCloud->new(); - my $base = Memories->config->uri_base."tag/view/"; - for my $tagging (Memories::Tagging->search_summary) { - my $name = $tagging->tag->name; - $cloud->add($name, - $base.uri_escape($name), - $tagging->{count} - ) - } - $cloud -} - -sub calendar { - # shift->do_cached(\&_calendar, shift ) } -#sub _calendar { - my $self = shift; - my $arg = shift; - my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd); - my @m = Calendar::Simple::calendar($m, $y); - my @month; - foreach my $week (@m) { - my @weekdays; - foreach my $day (@$week) { - my $d = { day => $day }; - if ($day) { - my $tag = "date:$y-$m-".sprintf("%02d", $day); - my ($x) = Memories::SystemTag->search(name => $tag); - if ($x) { $d->{tag} = "/system_tag/view/$tag" } - } - push(@weekdays, $d); - } - push(@month, \@weekdays); - } - return \@month; -} - -# THIS IS A HACK - -use Time::Seconds; -sub Time::Piece::next_month { - my $tp = shift; - my $month = $tp + ONE_MONTH; - return if $month > Time::Piece->new; - return $month -} -sub Time::Piece::prev_month { - my $tp = shift; - my $month = $tp - ONE_MONTH; - return $month -} - - sub tag_select { my ($r, $tags) = @_; my %counter; diff --git a/Tagtools.pm b/Tagtools.pm index 292e6e5..10a242b 100644 --- a/Tagtools.pm +++ b/Tagtools.pm @@ -1,4 +1,5 @@ package Tagtools; +use URI::Escape; use HTML::TagCloud; use Carp; use Cache::FileCache; @@ -53,7 +54,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}, @_) } } }