=head1 NAME
-WebPAC::Store - Store normalized data on disk
+WebPAC::Store - Store WebPAC data on disk
=head1 VERSION
-Version 0.09
+Version 0.10
=cut
-our $VERSION = '0.09';
+our $VERSION = '0.10';
=head1 SYNOPSIS
-This module provides disk storage for normalised data.
+This module provides disk storage for normalised data and lookups.
-It is newest component of WebPAC, so it will change quite often or be in
-flux. However, I will try to keep backward compatiblity by providing
-multiple back-ends.
+It is one of newer components of WebPAC, so it will change from time to
+time.
+
+I will try to keep backward compatiblity by providing multiple back-ends,
+but this can't be garanteed. In other words, don't delete your input
+databases just yet :-)
This has additional advantage. I can create single place to plugin other
file formats which provide better performance for particular type of data.
sub new {
my $class = shift;
- my $self = {@_};
- bless($self, $class);
+ my $self = {@_};
+ bless($self, $class);
my $log = $self->_get_logger();
my $cache_file = "$cache_path/$database/$prefix/$id";
$cache_file =~ s#//#/#go;
-open(my $fh, '>>', '/tmp/foo');
-print $fh "LOAD $cache_path / $database / $prefix / $id ==> $cache_file\n";
-close($fh);
-
$log->debug("using cache_file $cache_file");
if (-r $cache_file) {
}
+=head2 save_lookup
+
+ $db->save_lookup( $database, $input, $key, $lookup );
+
+=cut
+
+sub save_lookup {
+ my $self = shift;
+ my ($database, $input, $key, $lookup) = @_;
+
+ my $log = $self->_get_logger;
+
+ my $path = $self->{'path'} . "/lookup/$input";
+
+ mkpath($path) unless (-d $path);
+
+ $path .= "/$key";
+
+ if (store $lookup, $path) {
+ $log->info("saved lookup $path");
+ } else {
+ $log->logwarn("can't store lookup $database/$input/$key in $path: $!");
+ }
+
+
+}
+
+
=head1 AUTHOR
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
use WebPAC::Common 0.02;
use WebPAC::Parser 0.04;
use WebPAC::Input 0.13;
-use WebPAC::Store 0.03;
+use WebPAC::Store 0.10;
use WebPAC::Normalize 0.11;
use WebPAC::Output::TT;
use WebPAC::Validate 0.06;
$log->info("working on database '$database' in $db_path");
}
- my $db = new WebPAC::Store(
+ my $store = new WebPAC::Store(
path => $db_path,
database => $database,
debug => $debug,
foreach my $input (@inputs) {
- next if ($only_input && ($input->{name} !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
+ my $input_name = $input->{name} || $log->logdie("input without a name isn't valid: ",dump($input));
+
+ next if ($only_input && ($input_name !~ m#$only_input#i && $input->{type} !~ m#$only_input#i));
my $type = lc($input->{type});
my @lookups = $parser->have_lookup_create($database, $input);
- $log->info("working on input '$input->{name}' in $input->{path} [type: $input->{type}] using $input_module",
+ $log->info("working on input '$input_name' in $input->{path} [type: $input->{type}] using $input_module",
@lookups ? " creating lookups: ".join(", ", @lookups) : ""
);
$log->logdie("can't create input using $input_module") unless ($input);
if (defined( $input->{lookup} )) {
- $log->warn("$database/", $input->{name}, " has depriciated lookup definition, removing it...");
+ $log->warn("$database/$input_name has depriciated lookup definition, removing it...");
delete( $input->{lookup} );
}
%{ $input },
);
- $log->debug("created following lookups: ", dump( WebPAC::Normalize::_get_lookup() ) );
+ my $lookup_data = WebPAC::Normalize::_get_lookup();
+
+ $log->debug("created following lookups: ", dump( $lookup_data ));
+
+ foreach my $key (keys %$lookup_data) {
+ $store->save_lookup( $database, $input_name, $key, $lookup_data->{$key} );
+ }
my $report_fh;
if ($stats || $validate) {
- my $path = "out/report/" . $database . '-' . $input->{name} . '.txt';
+ my $path = "out/report/${database}-${input_name}.txt";
open($report_fh, '>', $path) || $log->logdie("can't open $path: $!");
- print $report_fh "Report for database '$database' input '$input->{name}' records ",
+ print $report_fh "Report for database '$database' input '$input_name' records ",
$offset || 1, "-", $limit || $input->{limit} || $maxmfn, "\n\n";
$log->info("Generating report file $path");
}
if ($marc_normalize) {
@norm_array = ( {
path => $marc_normalize,
- output => $marc_output || 'out/marc/' . $database . '-' . $input->{name} . '.marc',
+ output => $marc_output || "out/marc/${database}-${input_name}.marc",
} );
}
marc_encoding => 'utf-8',
);
- $db->save_ds(
+ $store->save_ds(
id => $mfn,
ds => $ds,
- prefix => $input->{name},
+ prefix => $input_name,
) if ($ds && !$stats);
$indexer->add(
- id => $input->{name} . "/" . $mfn,
+ id => "${input_name}/${mfn}",
ds => $ds,
type => $config->get($indexer_config)->{type},
) if ($indexer && $ds);