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

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

revision 43 by dpavlin, Sat Nov 12 21:32:03 2005 UTC revision 44 by dpavlin, Mon Nov 14 16:12:20 2005 UTC
# Line 43  For now, this is a prototype version. Line 43  For now, this is a prototype version.
43  Create new normalised database object  Create new normalised database object
44    
45    my $db = new WebPAC::DB(    my $db = new WebPAC::DB(
46          path = '/path/to/cache/ds/',          path => '/path/to/cache/ds/',
47            read_only => 1,
48    );    );
49    
50  Optional parameter C<path> defines path to directory  Optional parameter C<path> defines path to directory
51  in which cache file for C<data_structure> call will be created.  in which cache file for C<data_structure> call will be created.
52    
53    If called with C<read_only> it will not disable caching if
54    called without write permission (but will die on C<save_ds>).
55    
56  =cut  =cut
57    
58  sub new {  sub new {
# Line 86  sub path { Line 90  sub path {
90                  } elsif (! -d $dir) {                  } elsif (! -d $dir) {
91                          $msg = "is not directory";                          $msg = "is not directory";
92                  } elsif (! -w $dir) {                  } elsif (! -w $dir) {
93                          $msg = "not writable";                          $msg = "not writable" unless ($self->{'read_only'});
94                  }                  }
95    
96                  if ($msg) {                  if ($msg) {
# Line 127  sub load_ds { Line 131  sub load_ds {
131    
132          my $cache_path = $self->{'path'};          my $cache_path = $self->{'path'};
133    
134          my $id = $rec->{'000'};          my $id = $rec;
135          $id = $rec->{'000'}->[0] if ($id =~ m/^ARRAY/o);          $id = $rec->{'000'} if (ref($id) eq 'HASH');
136            $id = $rec->{'000'}->[0] if (ref($id) eq 'ARRAY');
137    
138          unless (defined($id)) {          unless (defined($id)) {
139                  $log->warn("Can't use cacheing on records without unique identifier in field 000");                  $log->warn("Can't use cacheing on records without unique identifier in field 000");
# Line 180  Depends on filename generated by C<load_ Line 185  Depends on filename generated by C<load_
185  sub save_ds {  sub save_ds {
186          my $self = shift;          my $self = shift;
187    
188            die "can't write to database in read_only mode!" if ($self->{'read_only'});
189    
190          return unless($self->{'path'});          return unless($self->{'path'});
191          return unless (@_);          return unless (@_);
192    

Legend:
Removed from v.43  
changed lines
  Added in v.44

  ViewVC Help
Powered by ViewVC 1.1.26