r1345@llin: dpavlin | 2007-10-10 21:01:02 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 10 Oct 2007 19:01:57 +0000 (19:01 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 10 Oct 2007 19:01:57 +0000 (19:01 +0000)
 and working parser

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@899 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input/ISI.pm
t/2-input-isi.t

index 62fd67a..6508394 100644 (file)
@@ -85,6 +85,37 @@ sub new {
 
        $log->info("opening $format $version database '$arg->{path}'");
 
+       my $tag;
+       my $rec;
+
+       while( $line = <$fh> ) {
+               chomp($line);
+
+               my $v;
+
+               if ( $line =~ /^(\S\S)\s(.+)$/ ) {
+                               $tag = $1;
+                               $v = $2;
+               } elsif ( $line =~ /^\s{3}(.+)$/ ) {
+                               $v = $1;
+               } elsif ( $line eq 'ER' ) {
+                       push @{ $self->{_rec} }, $rec;
+                       $rec = {};
+                       $line = <$fh>;
+                       chomp $line;
+                       $log->logdie("expected blank like in ",$arg->{path}, " +$.: $line") unless ( $line eq '' );
+               } elsif ( $line eq 'EF' ) {
+                       last;
+               } else {
+                       $log->logdie("can't parse +$. $arg->{path} : $line");
+               }
+
+               push @{ $rec->{$tag} }, $v;
+
+       }
+
+       $log->debug("loaded ", $self->size, " records");
+
        $self ? return $self : return undef;
 }
 
@@ -92,18 +123,16 @@ sub new {
 
 Return record with ID C<$mfn> from database
 
-  my $rec = $input->fetch_rec( $mfn, $filter_coderef);
+  my $rec = $input->fetch_rec( $mfn, $filter_coderef );
 
 =cut
 
 sub fetch_rec {
        my $self = shift;
 
-       my ($mfn, $filter_coderef) = @_;
-
-       my $rec;
+       my ( $mfn, $filter_coderef ) = @_;
 
-       return $rec;
+       return $self->{_rec}->[$mfn-1];
 }
 
 
@@ -117,7 +146,7 @@ Return number of records in database
 
 sub size {
        my $self = shift;
-       return 2;
+       return $#{$self->{_rec}} + 1;
 }
 
 =head1 AUTHOR
index d205a2c..90d5f71 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::More tests => 45;
+use Test::More tests => 9;
 use Test::Exception;
 use Cwd qw/abs_path/;
 use blib;