r11541@llin: dpavlin | 2005-12-05 16:47:44 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 5 Dec 2005 17:48:08 +0000 (17:48 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 5 Dec 2005 17:48:08 +0000 (17:48 +0000)
 added prefix [0.04]

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@219 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Normalize.pm

index d98ee70..bbc4094 100644 (file)
@@ -11,11 +11,11 @@ WebPAC::Normalize - data mungling for normalisation
 
 =head1 VERSION
 
-Version 0.03
+Version 0.04
 
 =cut
 
-our $VERSION = '0.03';
+our $VERSION = '0.04';
 
 =head1 SYNOPSIS
 
@@ -82,11 +82,15 @@ Create new normalisation object
        db => $db_obj,
        lookup_regex => $lookup->regex,
        lookup => $lookup_obj,
+       prefix => 'foobar',
   );
 
 Parametar C<filter> defines user supplied snippets of perl code which can
 be use with C<filter{...}> notation.
 
+C<prefix> is used to form filename for database record (to support multiple
+source files which are joined in one database).
+
 Recommended parametar C<lookup_regex> is used to enable parsing of lookups
 in structures. If you pass this parametar, you must also pass C<lookup>
 which is C<WebPAC::Lookup> object.
@@ -111,6 +115,8 @@ sub new {
 
        $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup'));
 
+       $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'});
+
        $self ? return $self : return undef;
 }
 
@@ -138,12 +144,12 @@ sub data_structure {
 
        $log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'}));
 
-       my $mfn = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!");
+       my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!");
 
        my $cache_file;
 
        if ($self->{'db'}) {
-               my $ds = $self->{'db'}->load_ds( id => $mfn );
+               my $ds = $self->{'db'}->load_ds( id => $id, prefix => $self->{prefix} );
                $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) });
                return $ds if ($ds);
                $log->debug("cache miss, creating");
@@ -249,8 +255,9 @@ sub data_structure {
        }
 
        $self->{'db'}->save_ds(
-               id => $mfn,
+               id => $id,
                ds => $ds,
+               prefix => $self->{prefix},
        ) if ($self->{'db'});
 
        $log->debug("ds: ", sub { Dumper($ds) });