/[webpac2]/trunk/lib/WebPAC/Input/Ovid.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/WebPAC/Input/Ovid.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1130 - (hide annotations)
Tue Apr 21 21:06:29 2009 UTC (15 years ago) by dpavlin
File size: 2541 byte(s)
 r1768@llin:  dpavlin | 2009-04-21 23:04:32 +0200
 hush debug output

1 dpavlin 1124 package WebPAC::Input::Ovid;
2    
3     use warnings;
4     use strict;
5    
6     use lib 'lib';
7     use WebPAC::Input;
8     use base qw/WebPAC::Common/;
9    
10     use Data::Dump qw/dump/;
11    
12     =head1 NAME
13    
14     WebPAC::Input::Ovid - support for Ovid citation export
15    
16     =head1 VERSION
17    
18     Version 0.01
19    
20     =cut
21    
22     our $VERSION = '0.01';
23 dpavlin 1130 our $debug = 0;
24 dpavlin 1124
25     =head1 SYNOPSIS
26    
27     Open file in Ovid citation export fromat
28    
29     my $input = new WebPAC::Input::Ovid(
30     path => '/path/to/ovid-cites.txt',
31     );
32    
33     =head1 FUNCTIONS
34    
35     =head2 new
36    
37     Returns new low-level input API object
38    
39     my $input = new WebPAC::Input::Ovid(
40     path => '/path/to/ebsco.txt',
41     filter => sub {
42     my ($l,$field_nr) = @_;
43     # do something with $l which is line of input file
44     return $l;
45     },
46     }
47    
48     Options:
49    
50     =over 4
51    
52     =item path
53    
54     path to Ovid export file
55    
56     =back
57    
58     =cut
59    
60     sub new {
61     my $class = shift;
62     my $self = {@_};
63     bless($self, $class);
64    
65     my $arg = {@_};
66    
67     my $log = $self->_get_logger();
68    
69     open( my $fh, '<', $arg->{path} ) || $log->logconfess("can't open $arg->{path}: $!");
70    
71     $log->info("reading '$arg->{path}'");
72    
73     my $rec;
74     my $size = 0;
75     my $tag;
76    
77     $self->{_rec} = [];
78    
79     while( my $line = <$fh> ) {
80     $line =~ s{[\r\n]+$}{};
81     next if $line eq '';
82    
83 dpavlin 1130 warn "<< $line\n" if $debug;
84 dpavlin 1124
85     if ( $line =~ m/^<(\d+)>$/ ) {
86 dpavlin 1126 push @{ $self->{_rec} }, $rec if $rec;
87 dpavlin 1130 warn "## rec = ",dump( $rec ),$/ if $debug;
88 dpavlin 1124 my $expect_rec = $#{ $self->{_rec} } + 2;
89 dpavlin 1130 warn "wrong Ovid record number: $1 != $expect_rec" if $debug && $1 != $expect_rec;
90 dpavlin 1126 $rec = { '000' => [ $1 ] };
91 dpavlin 1124 } elsif ( $line =~ /^(\w.+)/ ) {
92     $tag = $1;
93 dpavlin 1130 warn "++ $tag\n" if $debug;
94 dpavlin 1124 } elsif ( $line =~ /^\s\s(.+)/ ) {
95     my $v = $1;
96     $v =~ s{[\s\.]+$}{};
97 dpavlin 1126 $rec->{$tag} = [ $v ];
98 dpavlin 1124 } else {
99 dpavlin 1130 warn "### skip: '$line'\n" if $debug;
100 dpavlin 1124 }
101    
102     }
103    
104     # save last rec
105     push @{ $self->{_rec} }, $rec if $rec;
106    
107     $log->debug("loaded ", $self->size, " records");
108    
109     $self ? return $self : return undef;
110     }
111    
112     =head2 fetch_rec
113    
114     Return record with ID C<$mfn> from database
115    
116     my $rec = $input->fetch_rec( $mfn, $filter_coderef );
117    
118     =cut
119    
120     sub fetch_rec {
121     my $self = shift;
122    
123     my ( $mfn, $filter_coderef ) = @_;
124    
125     return $self->{_rec}->[$mfn-1];
126     }
127    
128    
129     =head2 size
130    
131     Return number of records in database
132    
133     my $size = $input->size;
134    
135     =cut
136    
137     sub size {
138     my $self = shift;
139 dpavlin 1126 return $#{ $self->{_rec} } + 1;
140 dpavlin 1124 }
141    
142     =head1 AUTHOR
143    
144     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
145    
146     =head1 COPYRIGHT & LICENSE
147    
148     Copyright 2008 Dobrica Pavlinusic, All Rights Reserved.
149    
150     This program is free software; you can redistribute it and/or modify it
151     under the same terms as Perl itself.
152    
153     =cut
154    
155     1; # End of WebPAC::Input::Ovid

  ViewVC Help
Powered by ViewVC 1.1.26