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<path> defines path to directory
in which cache file for C<data_structure> call will be created.
+If called with C<read_only> it will not disable caching if
+called without write permission (but will die on C<save_ds>).
+
=cut
sub new {
} elsif (! -d $dir) {
$msg = "is not directory";
} elsif (! -w $dir) {
- $msg = "not writable";
+ $msg = "not writable" unless ($self->{'read_only'});
}
if ($msg) {
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");
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 (@_);