1 package WebPAC::Input::Koha;
8 use base qw/WebPAC::Common/;
10 use Data::Dump qw/dump/;
14 WebPAC::Input::Koha - read MARC records from Koha
18 our $VERSION = '0.01';
24 my $input = new WebPAC::Input::Koha(
38 my $log = $self->_get_logger();
40 if ( -e $arg->{path} ) {
41 $log->info("Koha marc dump ", $arg->{path}, " exists");
42 $self->{_koha_size} = 0;
45 $log->info("opening Koha database '$arg->{dsn}'");
47 $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, { RaiseError => 1 } );
48 $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );
49 $self->{_sth}->execute;
50 $self->{_koha_size} = $self->{_sth}->rows;
52 warn "got ", $self->{_koha_size}, " rows for ", $arg->{sql};
54 open( $self->{_koha_fh}, '>', $arg->{path} ) || die "can't create $arg->{path}: $!";
58 $self ? return $self : return undef;
63 Return record with ID C<$mfn> from database
65 my $rec = $input->fetch_rec( $mfn );
74 my $row = $self->{_sth}->fetchrow_hashref;
76 if ( my $fh = $self->{_koha_fh} ) {
77 if ( my $marc = $row->{marc} ) {
80 warn "MFN $mfn no marc in ",dump($row);
84 push @{$row->{'000'}}, $mfn;
90 Return number of records in database
92 my $size = $isis->size;
98 return $self->{_koha_size};
104 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
106 =head1 COPYRIGHT & LICENSE
108 Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
110 This program is free software; you can redistribute it and/or modify it
111 under the same terms as Perl itself.