hash_filter now gets record number as second arguments to be in sync with Biblio...
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Jul 2006 14:00:23 +0000 (14:00 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 13 Jul 2006 14:00:23 +0000 (14:00 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/MARC-Fast/trunk@9 49f9634a-d7ec-0310-8e6b-ec35c6cc8804

Fast.pm
META.yml
t/001_marc.t

diff --git a/Fast.pm b/Fast.pm
index 7f2a618..e9a7142 100644 (file)
--- a/Fast.pm
+++ b/Fast.pm
@@ -7,7 +7,7 @@ use Data::Dumper;
 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 ();
@@ -43,7 +43,7 @@ Read MARC database
        debug => 0,
        assert => 0,
        hash_filter => sub {
-               my $t = shift;
+               my ($t, $record_number) = @_;
                $t =~ s/foo/bar/;
                return $t;
        },
@@ -270,14 +270,14 @@ sub to_hash {
 
        my $row = $self->fetch($mfn) || return;
 
-       foreach my $k (keys %{$row}) {
-               foreach my $l (@{$row->{$k}}) {
+       foreach my $rec_nr (keys %{$row}) {
+               foreach my $l (@{$row->{$rec_nr}}) {
 
                        # remove end marker
                        $l =~ s/\x1E$//;
 
                        # filter output
-                       $l = $self->{'hash_filter'}->($l) if ($self->{'hash_filter'});
+                       $l = $self->{'hash_filter'}->($l, $rec_nr) if ($self->{'hash_filter'});
 
                        my $val;
 
@@ -294,7 +294,7 @@ sub to_hash {
                                        # of this record. Then, new record with same
                                        # identifiers will be created.
                                        if ($val->{$f}) {
-                                               push @{$rec->{$k}}, $val;
+                                               push @{$rec->{$rec_nr}}, $val;
                                                $val = {
                                                        i1 => $val->{i1},
                                                        i2 => $val->{i2},
@@ -306,7 +306,7 @@ sub to_hash {
                                $val = $l;
                        }
 
-                       push @{$rec->{$k}}, $val;
+                       push @{$rec->{$rec_nr}}, $val;
                }
        }
 
index 468eebc..1e9c3a0 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -1,7 +1,7 @@
 # http://module-build.sourceforge.net/META-spec.html
 #XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
 name:         MARC-Fast
-version:      0.02
+version:      0.03
 version_from: Fast.pm
 installdirs:  site
 requires:
index 691a3a2..2b952a5 100755 (executable)
@@ -27,6 +27,8 @@ SKIP: {
 
        isa_ok ($marc, 'MARC::Fast');
 
+       #diag Dumper($marc);
+
        cmp_ok($marc->count, '==', scalar @{$marc->{leaders}}, "count == leaders");
        cmp_ok($marc->count, '==', scalar @{$marc->{fh_offset}}, "count == fh_offset");
 
@@ -36,5 +38,8 @@ SKIP: {
 
        foreach (1 .. 10) {
                ok($marc->fetch($_), "fetch $_");
+
+               ok(my $hash = $marc->to_hash($_), "to_hash $_");
+               diag "$_ :: ",Dumper($hash);
        }
 }