added to_ascii to be more like Biblio::ISIS API [0.05]
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 3 Nov 2006 20:34:31 +0000 (20:34 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 3 Nov 2006 20:34:31 +0000 (20:34 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/MARC-Fast/trunk@11 49f9634a-d7ec-0310-8e6b-ec35c6cc8804

Fast.pm
scripts/dump_fastmarc.pl
t/001_marc.t

diff --git a/Fast.pm b/Fast.pm
index e9a7142..4ac67e9 100644 (file)
--- a/Fast.pm
+++ b/Fast.pm
@@ -1,5 +1,5 @@
-
 package MARC::Fast;
+
 use strict;
 use Carp;
 use Data::Dumper;
@@ -7,7 +7,7 @@ use Data::Dumper;
 BEGIN {
        use Exporter ();
        use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
-       $VERSION     = 0.04;
+       $VERSION     = 0.05;
        @ISA         = qw (Exporter);
        #Give a hoot don't pollute, do not export more than needed by default
        @EXPORT      = qw ();
@@ -313,17 +313,32 @@ sub to_hash {
        return $rec;
 }
 
+=head2 to_ascii
 
-1;
-__END__
+  print $marc->to_ascii( 42 );
+
+=cut
 
-=head1 BUGS
+sub to_ascii {
+       my $self = shift;
 
+       my $mfn = shift || confess "need mfn";
+       my $row = $self->fetch($mfn) || return;
 
+       my $out;
 
-=head1 SUPPORT
+       foreach my $f (sort keys %{$row}) {
+               my $dump = join('', @{ $row->{$f} });
+               $dump =~ s/\x1e$//;
+               $dump =~ s/\x1f/\$/g;
+               $out .= "$f\t$dump\n";
+       }
 
+       return $out;
+}
 
+1;
+__END__
 
 =head1 AUTHOR
 
@@ -343,6 +358,6 @@ LICENSE file included with this module.
 
 =head1 SEE ALSO
 
-perl(1).
+L<Biblio::Isis>, perl(1).
 
 =cut
index b1d8702..1f0605d 100755 (executable)
@@ -67,12 +67,6 @@ for my $mfn ($min .. $max) {
        my $rec = $marc->fetch($mfn) || next;
        print "rec is ",Dumper($rec) if ($opt{d});
        print "REC $mfn\n";
-       foreach my $f (sort keys %{$rec}) {
-               my $dump = join('', @{ $rec->{$f} });
-               $dump =~ s/\x1e$//;
-               $dump =~ s/\x1f/\$/g;
-               print "$f\t$dump\n";
-       }
-       print "\n";
+       print $marc->to_ascii($mfn),"\n";
        print "hash is ",Dumper($marc->to_hash($mfn)) if ($opt{h});
 }
index 2b952a5..7a665dc 100755 (executable)
@@ -3,12 +3,14 @@
 use strict;
 use blib;
 
-use Test::More tests => 20;
+use Test::More tests => 40;
 use Test::Exception;
-use Data::Dumper;
+use Data::Dump qw/dump/;
 
 BEGIN { use_ok( 'MARC::Fast' ); }
 
+my $debug = shift @ARGV;
+
 my $marc;
 my %param;
 
@@ -40,6 +42,8 @@ SKIP: {
                ok($marc->fetch($_), "fetch $_");
 
                ok(my $hash = $marc->to_hash($_), "to_hash $_");
-               diag "$_ :: ",Dumper($hash);
+               diag "to_hash($_) = ",dump($hash) if ($debug);
+               ok(my $ascii = $marc->to_ascii($_), "to_ascii $_");
+               diag "to_ascii($_) ::\n$ascii" if ($debug);
        }
 }