/[A3C]/lib/Strix.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 216 by dpavlin, Fri Jun 20 21:49:16 2008 UTC revision 219 by dpavlin, Sun Jun 22 14:41:23 2008 UTC
# Line 3  package Strix; Line 3  package Strix;
3  use strict;  use strict;
4  use warnings;  use warnings;
5    
6  use base qw(Jifty::Object Class::Accessor::Fast);  use base qw(Jifty::Object Class::Accessor::Fast A3C::Cache);
7  __PACKAGE__->mk_accessors( qw(instance uid) );  __PACKAGE__->mk_accessors( qw(instance uid) );
8    
9  use DBI;  use DBI;
# Line 11  use Data::Dump qw/dump/; Line 11  use Data::Dump qw/dump/;
11  use Carp qw/confess/;  use Carp qw/confess/;
12  use Jifty;  use Jifty;
13    
 use File::Slurp;  
 use JSON::XS;  
14  use Carp qw/confess/;  use Carp qw/confess/;
15  use URI::Escape;  use URI::Escape;
16    
# Line 330  sub site_navigation { Line 328  sub site_navigation {
328    
329  }  }
330    
 =head2 cache_path  
   
 Generate unique name for specified values  
   
   my $path = $strix->cache_path( $var, ... );  
   
 Variables have to be path-safe (e.g. use C<uri_encode> if needed)  
   
 =cut  
   
 sub cache_path {  
         my $self = shift;  
   
         #warn "# cache_path",dump( @_ );  
   
         my $path = Jifty::Util->absolute_path( 'var/strix' );  
   
         if ( ! -e $path ) {  
                 mkdir $path || die "can't create $path: $!";  
         }  
   
         #warn "## caller = ",dump( (caller(2))[3] );  
         my $uid = (caller(2))[3];  
         $uid =~ s/^[^:]+:://;  
         $uid .= '-' . join('-', @_) if @_;  
         $uid .= '.js';  
   
         return $path . '/' . $self->instance . '-' . $uid;  
 }  
   
 =head2 write_cache  
   
   write_cache( $data, $key_var, ... );  
   
 =cut  
   
 sub write_cache {  
         my $self = shift;  
         my $data = shift || confess "no data?";  
         my $path = $self->cache_path( @_ );  
         write_file( $path, encode_json( $data )) || die "can't save into $path: $!";  
 }  
   
 =head2 read_cache  
   
         my $data = read_cache( 'format-%d', $var ... );  
   
 =cut  
   
 sub read_cache {  
         my $self = shift;  
         my $path = $self->cache_path( @_ );  
         return unless -e $path;  
         #warn "# read_cache( $path )";  
         return decode_json( read_file( $path ) ) || die "can't read $path: $!";  
 }  
   
331  1;  1;

Legend:
Removed from v.216  
changed lines
  Added in v.219

  ViewVC Help
Powered by ViewVC 1.1.26