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 { |
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) { |
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"); |
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 |
|
|