--- trunk/IsisDB.pm 2004/12/29 17:03:52 11 +++ trunk/IsisDB.pm 2004/12/29 20:10:11 12 @@ -7,7 +7,7 @@ BEGIN { use Exporter (); use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); - $VERSION = 0.03; + $VERSION = 0.04; @ISA = qw (Exporter); #Give a hoot don't pollute, do not export more than needed by default @EXPORT = qw (); @@ -70,8 +70,12 @@ my $isis = new IsisDB( isisdb => './cds/cds', read_fdt => 1, - debug => 1, include_deleted => 1, + hash_filter => sub { + my $v = shift; + $v =~ s#foo#bar#g; + }, + debug => 1, ); Options are described below: @@ -88,14 +92,18 @@ Boolean flag to specify if field definition table should be read. It's off by default. -=item debug - -Dump a C of debugging output. - =item include_deleted Don't skip logically deleted records in ISIS. +=item hash_filter + +Filter code ref which will be used before data is converted to hash. + +=item debug + +Dump a B of debugging output. + =back It will also set C<$isis-E{'maxmfn'}> which is maximum MFN stored in database. @@ -109,7 +117,7 @@ croak "new needs database name (isisdb) as argument!" unless ({@_}->{isisdb}); - foreach my $v (qw{isisdb debug include_deleted}) { + foreach my $v (qw{isisdb debug include_deleted hash_filter}) { $self->{$v} = {@_}->{$v}; } @@ -223,7 +231,7 @@ my $rec = $isis->fetch(55); Returns hash with keys which are field names and values are unpacked values -for that field. +for that field (like C<^asometing^bsomething else>) =cut @@ -378,6 +386,69 @@ return $out; } +=head2 to_hash + +Read mfn and convert it to hash + + my $hash = $isis->to_hash($mfn); + +It has ability to convert characters (using C from ISIS +database before creating structures enabling character remapping or quick +fixup of data. + +This function returns hash which is like this: + + $hash = { + '210' => [ + { + 'c' => 'New York University press', + 'a' => 'New York', + 'd' => 'cop. 1988' + } + ], + '990' => [ + '2140', + '88', + 'HAY' + ], + }; + +You can later use that has to produce any output from ISIS data. + +=cut + +sub to_hash { + my $self = shift; + + my $mfn = shift || confess "need mfn!"; + + my $rec; + my $row = $self->fetch($mfn); + + foreach my $k (keys %{$row}) { + foreach my $l (@{$row->{$k}}) { + + # filter output + $l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'}); + + # has subfields? + my $val; + if ($l =~ m/\^/) { + foreach my $t (split(/\^/,$l)) { + next if (! $t); + $val->{substr($t,0,1)} = substr($t,1); + } + } else { + $val = $l; + } + + push @{$rec->{$k}}, $val; + } + } + + return $rec; +} + # # XXX porting from php left-over: #