1 package WebPAC::Input::AK;
7 use base qw/WebPAC::Common/;
9 use Data::Dump qw/dump/;
14 WebPAC::Input::AK - support for AK Export Format
18 our $VERSION = '0.01';
25 Open file in AK export fromat
27 my $input = new WebPAC::Input::AK(
28 path => '/path/to/AK/records.txt',
35 Returns new low-level input API object
37 my $input = new WebPAC::Input::AK(
38 path => '/path/to/AK/records.txt'
40 my ($l,$field_nr) = @_;
41 # do something with $l which is line of input file
52 path to AK export file
65 open( my $fh, '<', $arg->{path} ) || confess "can't open $arg->{path}: $!";
68 $self->{record_offset} = [];
69 $self->{offset} ||= 0;
73 while( my $line = <$fh> ) {
75 if ( $line =~ m/^\s*ISBN/ ) {
76 push @{ $self->{record_offset} }, $tell;
77 last if $self->{limit} && $#{ $self->{record_offset} } >= $self->{limit} - 1 + $self->{offset};
82 warn "I $arg->{path} read ", tell($fh), " bytes $#{ $self->{record_offset} } records\n";
91 Return record with ID C<$mfn> from database
93 my $rec = $input->fetch_rec( $mfn, $filter_coderef );
98 my ( $self, $mfn, $filter_coderef ) = @_;
100 my $fh = $self->{fh};
102 seek $fh, $self->{record_offset}->[ $mfn - 1 ], 0;
108 while( my $line = <$fh> ) {
118 $rec->{'000'} = [ $mfn ];
119 warn "## mfn $mfn" if $debug;
125 if ( $line =~ m/^\s{19}(.*)/ ) {
127 } elsif ( $line =~ m/^\s*(\S+.+):\s(.+)/ ) {
136 confess "can't parse ",dump($line);
146 Return number of records in database
148 my $size = $input->size;
154 my $size = $#{ $self->{record_offset} };
155 return 0 if $size < 0;
156 # no need for +1 since we record end of file as last record
157 return $size - $self->{offset};
163 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
165 =head1 COPYRIGHT & LICENSE
167 Copyright 2015 Dobrica Pavlinusic, All Rights Reserved.
169 This program is free software; you can redistribute it and/or modify it
170 under the same terms as Perl itself.
174 1; # End of WebPAC::Input::AK