/[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 714 by dpavlin, Tue Sep 26 12:47:52 2006 UTC revision 716 by dpavlin, Tue Sep 26 14:07:20 2006 UTC
# Line 14  WebPAC::Store - Store WebPAC data on dis Line 14  WebPAC::Store - Store WebPAC data on dis
14    
15  =head1 VERSION  =head1 VERSION
16    
17  Version 0.11  Version 0.12
18    
19  =cut  =cut
20    
21  our $VERSION = '0.11';  our $VERSION = '0.12';
22    
23  =head1 SYNOPSIS  =head1 SYNOPSIS
24    
# Line 215  Store data_structure on disk. Line 215  Store data_structure on disk.
215          ds => $ds,          ds => $ds,
216    );    );
217    
218  B<Totally broken, but fast.>  C<database> and C<input> are optional.
   
 Depends on filename generated by C<load_ds>.  
219    
220  =cut  =cut
221    
# Line 258  sub save_ds { Line 256  sub save_ds {
256    
257  }  }
258    
259    =head2 load_lookup
260    
261    Loads lookup hash from file
262    
263      $data = $db->load_lookup(
264            database => $database,
265            input => $input,
266            key => $key,
267      );
268    
269    C<database> is optional.
270    
271    =cut
272    
273    sub load_lookup {
274            my $self = shift;
275            my $args = {@_};
276    
277            my $log = $self->_get_logger;
278    
279            foreach my $r (qw/input key/) {
280                    $log->logconfess("need '$r'") unless defined($args->{$r});
281            }
282    
283            my $database = $args->{database} || $self->{database} || $log->logconfess("no database?");
284    
285            my $path = $self->{path} . "/lookup/$database/" . $args->{input} . '/' . $args->{key};
286    
287            if (! -e $path) {
288                    $log->warn("lookup $path doesn't exist, skipping");
289                    return;
290            }
291    
292            if (my $data = retrieve($path)) {
293                    $log->info("loaded lookup $path");
294                    return $data;
295            } else {
296                    $log->logwarn("can't load lookup $database/", $args->{input}, "/", $args->{key}, " from $path: $!");
297                    return undef;
298            }
299    }
300    
301  =head2 save_lookup  =head2 save_lookup
302    
303    Save lookup data to file.
304    
305    $db->save_lookup(    $db->save_lookup(
306          database => $database,          database => $database,
307          input => $input,          input => $input,
# Line 267  sub save_ds { Line 309  sub save_ds {
309          data => $lookup,          data => $lookup,
310    );    );
311    
312    C<database> is optional.
313    
314  =cut  =cut
315    
316  sub save_lookup {  sub save_lookup {
# Line 291  sub save_lookup { Line 335  sub save_lookup {
335                  $log->info("saved lookup $path");                  $log->info("saved lookup $path");
336                  return 1;                  return 1;
337          } else {          } else {
338                  $log->logwarn("can't store lookup $database/", $args->{input}, "/", $args->{key}, " in $path: $!");                  $log->logwarn("can't save lookup $database/", $args->{input}, "/", $args->{key}, " in $path: $!");
339                  return undef;                  return undef;
340          }          }
341  }  }
# Line 303  Dobrica Pavlinusic, C<< <dpavlin@rot13.o Line 347  Dobrica Pavlinusic, C<< <dpavlin@rot13.o
347    
348  =head1 COPYRIGHT & LICENSE  =head1 COPYRIGHT & LICENSE
349    
350  Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.  Copyright 2005-2006 Dobrica Pavlinusic, All Rights Reserved.
351    
352  This program is free software; you can redistribute it and/or modify it  This program is free software; you can redistribute it and/or modify it
353  under the same terms as Perl itself.  under the same terms as Perl itself.

Legend:
Removed from v.714  
changed lines
  Added in v.716

  ViewVC Help
Powered by ViewVC 1.1.26