--- /dev/null
+package WebPAC::Input::Koha;
+
+use warnings;
+use strict;
+
+use DBI;
+use MARC::Fast;
+use base qw/WebPAC::Common/;
+use Carp qw/confess/;
+
+=head1 NAME
+
+WebPAC::Input::Koha - read MARC records from Koha
+
+=cut
+
+our $VERSION = '0.01';
+
+=head1 FUNCTIONS
+
+=head2 new
+
+ my $input = new WebPAC::Input::Koha(
+ dsn => '',
+ filter => \&code_ref,
+ }
+
+=cut
+
+sub new {
+ my $class = shift;
+ my $self = {@_};
+ bless($self, $class);
+
+ my $arg = {@_};
+
+ my $log = $self->_get_logger();
+
+ $log->info("opening Koha database '$arg->{dsn}'");
+
+ $self->{_dbh} = DBI->connect( $arg->{dsn}, $arg->{user}, $arg->{passwd}, { RaiseError => 1 } );
+ $self->{_sth} = $self->{_dbh}->prepare( $arg->{sql} );
+ $self->{_sth}->execute;
+
+ warn "got ", $self->{_sth}->rows, " rows for ", $arg->{sql};
+
+ open( $self->{_koha_fh}, '>', $arg->{path} ) || warn "not creating $arg->{path}: $!";
+
+ $self ? return $self : return undef;
+}
+
+=head2 fetch_rec
+
+Return record with ID C<$mfn> from database
+
+ my $rec = $input->fetch_rec( $mfn );
+
+=cut
+
+sub fetch_rec {
+ my $self = shift;
+
+ my $mfn = shift;
+
+ my $row = $self->{_sth}->fetchrow_hashref;
+
+ if ( my $fh = $self->{_koha_fh} ) {
+ my $marc = $row->{marc} || die "no marc?";
+ print $fh $marc;
+ }
+
+ push @{$row->{'000'}}, $mfn;
+ return $row;
+}
+
+=head2 size
+
+Return number of records in database
+
+ my $size = $isis->size;
+
+=cut
+
+sub size {
+ my $self = shift;
+ return $self->{_sth}->rows;
+}
+
+
+=head1 AUTHOR
+
+Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 Dobrica Pavlinusic, All Rights Reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use lib 'lib';
+
+use Test::More tests => 27;
+
+BEGIN {
+use_ok( 'WebPAC::Test' );
+use_ok( 'WebPAC::Input' );
+}
+
+my $module = 'WebPAC::Input::Koha';
+diag "testing with $module";
+
+ok(my $input = new WebPAC::Input(
+ module => $module,
+ no_progress_bar => 1,
+ %LOG
+), "new");
+
+ok(my $db = $input->open(
+ path => '/tmp/koha.marc', # required?
+ dsn => 'dbi:mysql:database=koha',
+ user => $ENV{KOHA_USER},
+ passwd => $ENV{KOHA_PASSWD},
+ sql => q{
+ select biblioitemnumber as mfn, marc from biblioitems limit 7
+ },
+), "open");
+ok(my $size = $input->size, "size");
+cmp_ok( $size, '==', 7, 'size ok' );
+
+foreach my $mfn ( 1 ... $size ) {
+ my $rec = $input->fetch;
+ ok($rec, "fetch $mfn");
+ cmp_ok($rec->{'000'}->[0], '==', $mfn, 'has mfn');
+ cmp_ok($input->pos, '==', $mfn, "pos $mfn");
+ diag "rec: ", dump($rec), "\n" if $debug;
+}
+