/[webpac2]/trunk/lib/WebPAC/Store.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 /trunk/lib/WebPAC/Store.pm

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

revision 217 by dpavlin, Mon Dec 5 17:47:51 2005 UTC revision 218 by dpavlin, Mon Dec 5 17:48:00 2005 UTC
# Line 14  WebPAC::Store - Store normalized data on Line 14  WebPAC::Store - Store normalized data on
14    
15  =head1 VERSION  =head1 VERSION
16    
17  Version 0.05  Version 0.06
18    
19  =cut  =cut
20    
21  our $VERSION = '0.05';  our $VERSION = '0.06';
22    
23  =head1 SYNOPSIS  =head1 SYNOPSIS
24    
# Line 56  in which cache file for C<data_structure Line 56  in which cache file for C<data_structure
56  If called with C<read_only> it will not disable caching if  If called with C<read_only> it will not disable caching if
57  called without write permission (but will die on C<save_ds>).  called without write permission (but will die on C<save_ds>).
58    
59    Mandatory parametar C<database> is used as subdirectory in database directory.
60    
61  =cut  =cut
62    
63  sub new {  sub new {
# Line 63  sub new { Line 65  sub new {
65          my $self = {@_};          my $self = {@_};
66          bless($self, $class);          bless($self, $class);
67    
68            my $log = $self->_get_logger();
69    
70            foreach my $p (qw/path database/) {
71                    $log->logconfess("need $p") unless ($self->{$p});
72            }
73    
74          $self->path( $self->{'path'} );          $self->path( $self->{'path'} );
75    
76          $self ? return $self : return undef;          $self ? return $self : return undef;
# Line 120  sub path { Line 128  sub path {
128    
129  Retrive from disk one data_structure records usually using field 000 as key  Retrive from disk one data_structure records usually using field 000 as key
130    
131    my $ds = $db->load_ds( id => 42, database => 'name' );    my $ds = $db->load_ds( id => 42, prefix => 'name' );
132    
133  This function will also perform basic sanity checking on returned  This function will also perform basic sanity checking on returned
134  data and disable caching if data is corrupted (or changed since last  data and disable caching if data is corrupted (or changed since last
135  update).  update).
136    
137    C<prefix> is used to differenciate different source input databases
138    which are indexed in same database.
139    
140  Returns hash or undef if cacheing is disabled or unavailable.  Returns hash or undef if cacheing is disabled or unavailable.
141    
142  =cut  =cut
# Line 148  sub load_ds { Line 159  sub load_ds {
159          my $id = $args->{id};          my $id = $args->{id};
160    
161          $log->logconfess("got hash, but without id") unless (defined($id));          $log->logconfess("got hash, but without id") unless (defined($id));
162          $log->logconfess("got hash, but id isn't number") unless ($id =~ /^\d+$/);          $log->logconfess("got hash, but id [$id] isn't number") unless ($id =~ /^\d+$/);
163    
164          my $database = $args->{database} || $self->{database};          my $database = $self->{database};
165            my $prefix = $args->{prefix} || '';
166    
167          $log->logconfess("can't find database name") unless ($database);          $log->logconfess("can't find database name") unless ($database);
168    
169          my $cache_file = "$cache_path/$database#$id";          my $cache_file = "$cache_path/$prefix/$database#$id";
170          $cache_file =~ s#//#/#g;          $cache_file =~ s#//#/#go;
171    
172    open(my $fh, '>>', '/tmp/foo');
173    print $fh "$cache_file\n";
174    close($fh);
175    
176          $log->debug("using cache_file $cache_file");          $log->debug("using cache_file $cache_file");
177    
# Line 184  Store data_structure on disk. Line 200  Store data_structure on disk.
200    
201    $db->save_ds(    $db->save_ds(
202          id => $ds->{000}->[0],          id => $ds->{000}->[0],
203          database => 'name',          prefix => 'name',
204          ds => $ds,          ds => $ds,
205    );    );
206    
# Line 209  sub save_ds { Line 225  sub save_ds {
225                  $log->logconfess("need $f") unless ($arg->{$f});                  $log->logconfess("need $f") unless ($arg->{$f});
226          }          }
227    
228          my $database = $arg->{database} ||  $self->{database};          my $database = $self->{database};
229          $log->logconfess("can't find database name") unless ($database);          $log->logconfess("can't find database name") unless ($database);
230    
231          my $cache_file = $self->{path} . '/' . $database . '#' . $arg->{id};          my $prefix = $arg->{prefix} || '';
232    
233            my $cache_file = $self->{path} . "/$prefix/$database#" . $arg->{id};
234            $cache_file =~ s#//#/#go;
235    
236          $log->debug("creating storable cache file $cache_file");          $log->debug("creating storable cache file $cache_file");
237    

Legend:
Removed from v.217  
changed lines
  Added in v.218

  ViewVC Help
Powered by ViewVC 1.1.26