/[webpac2]/trunk/lib/WebPAC/Input/XML.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/XML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 968 - (hide annotations)
Fri Nov 2 13:59:10 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 1925 byte(s)
 r1479@llin:  dpavlin | 2007-11-02 14:59:05 +0100
 begin work on WebPAC::Input::XML

1 dpavlin 968 package WebPAC::Input::XML;
2    
3     use warnings;
4     use strict;
5    
6     use WebPAC::Input;
7     use base qw/WebPAC::Common/;
8    
9     use XML::Simple;
10     use File::Find;
11    
12     use Data::Dump qw/dump/;
13    
14     =head1 NAME
15    
16     WebPAC::Input::XML - support for reading XML files
17    
18     =cut
19    
20     our $VERSION = '0.01';
21    
22     =head1 FUNCTIONS
23    
24     =head2 new
25    
26     Returns new low-level input API object
27    
28     my $input = new WebPAC::Input::XML(
29     path => '/path/to/XML/records.txt'
30     filter => sub {
31     my ($l,$field_nr) = @_;
32     # do something with $l which is line of input file
33     return $l;
34     },
35     }
36    
37     Options:
38    
39     =over 4
40    
41     =item path
42    
43     path to directory with xml files ending in C<.xml>
44    
45     =back
46    
47     =cut
48    
49     sub new {
50     my $class = shift;
51     my $self = {@_};
52     bless($self, $class);
53    
54     my $arg = {@_};
55    
56     my $log = $self->_get_logger();
57    
58     $log->logdie("can't find path ", $arg->{path}, ": $!\n") unless -d $arg->{path};
59    
60     $log->info("collecting xml files from ", $arg->{path});
61    
62     my @files;
63    
64     find({
65     wanted => sub {
66     my $path = $File::Find::name;
67     return unless -f $path && $path =~ m/\.xml$/i;
68     push @files, $path;
69     },
70     follow => 1,
71     }, $arg->{path} );
72    
73     $log->info("found ", $#files + 1, " XML files in ", $arg->{path});
74    
75     $self->{_files} = \@files;
76    
77     $self ? return $self : return undef;
78     }
79    
80     =head2 fetch_rec
81    
82     Return record with ID C<$mfn> from database
83    
84     my $rec = $input->fetch_rec( $mfn, $filter_coderef );
85    
86     =cut
87    
88     sub fetch_rec {
89     my $self = shift;
90    
91     my ( $mfn, $filter_coderef ) = @_;
92    
93     my $path = $self->{_files}->[ $mfn - 1 ] || return;
94    
95     warn "### fetch_rec( $mfn ) = $path";
96    
97     }
98    
99    
100     =head2 size
101    
102     Return number of records in database
103    
104     my $size = $input->size;
105    
106     =cut
107    
108     sub size {
109     my $self = shift;
110     return $#{$self->{_files}} + 1;
111     }
112    
113     =head1 AUTHOR
114    
115     Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
116    
117     =head1 COPYRIGHT & LICENSE
118    
119     Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
120    
121     This program is free software; you can redistribute it and/or modify it
122     under the same terms as Perl itself.
123    
124     =cut
125    
126     1;

  ViewVC Help
Powered by ViewVC 1.1.26