--- trunk/lib/WebPAC/DB.pm 2005/11/12 21:32:03 40 +++ trunk/lib/WebPAC/DB.pm 2005/11/14 16:12:20 44 @@ -43,12 +43,16 @@ Create new normalised database object my $db = new WebPAC::DB( - path = '/path/to/cache/ds/', + path => '/path/to/cache/ds/', + read_only => 1, ); Optional parameter C defines path to directory in which cache file for C call will be created. +If called with C it will not disable caching if +called without write permission (but will die on C). + =cut sub new { @@ -86,7 +90,7 @@ } elsif (! -d $dir) { $msg = "is not directory"; } elsif (! -w $dir) { - $msg = "not writable"; + $msg = "not writable" unless ($self->{'read_only'}); } if ($msg) { @@ -127,8 +131,9 @@ my $cache_path = $self->{'path'}; - my $id = $rec->{'000'}; - $id = $rec->{'000'}->[0] if ($id =~ m/^ARRAY/o); + my $id = $rec; + $id = $rec->{'000'} if (ref($id) eq 'HASH'); + $id = $rec->{'000'}->[0] if (ref($id) eq 'ARRAY'); unless (defined($id)) { $log->warn("Can't use cacheing on records without unique identifier in field 000"); @@ -180,6 +185,8 @@ sub save_ds { my $self = shift; + die "can't write to database in read_only mode!" if ($self->{'read_only'}); + return unless($self->{'path'}); return unless (@_);