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 ();
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:
Boolean flag to specify if field definition table should be read. It's off
by default.
-=item debug
-
-Dump a C<lot> 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<lot> of debugging output.
+
=back
It will also set C<$isis-E<gt>{'maxmfn'}> which is maximum MFN stored in database.
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};
}
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
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<hash_filter> 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:
#