From be2299900879d2c12a99cb9728a9113c85c6d8e8 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 3 Nov 2006 20:34:31 +0000 Subject: [PATCH] added to_ascii to be more like Biblio::ISIS API [0.05] git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/MARC-Fast/trunk@11 49f9634a-d7ec-0310-8e6b-ec35c6cc8804 --- Fast.pm | 29 ++++++++++++++++++++++------- scripts/dump_fastmarc.pl | 8 +------- t/001_marc.t | 10 +++++++--- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Fast.pm b/Fast.pm index e9a7142..4ac67e9 100644 --- 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, perl(1). =cut diff --git a/scripts/dump_fastmarc.pl b/scripts/dump_fastmarc.pl index b1d8702..1f0605d 100755 --- a/scripts/dump_fastmarc.pl +++ b/scripts/dump_fastmarc.pl @@ -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}); } diff --git a/t/001_marc.t b/t/001_marc.t index 2b952a5..7a665dc 100755 --- a/t/001_marc.t +++ b/t/001_marc.t @@ -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); } } -- 2.20.1