« Koha/Contrib/Sudoc/PPNize/Reader.pm
↑ Summary
auto/share/dist/Koha-Contrib-Sudoc/lib/BibliConverter.pm »
| 1 | package Koha::Contrib::Sudoc::BiblioReader; | ||
| 2 | #ABSTRACT: Lecture des notices biblio/autorité | ||
| 3 | $Koha::Contrib::Sudoc::BiblioReader::VERSION = '2.50'; | ||
| 4 | use Moose; | ||
| 5 | use Moose::Util::TypeConstraints; | ||
| 6 | use MARC::Moose::Record; | ||
| 7 | use MARC::Moose::Parser::Iso2709; | ||
| 8 | |||
| 9 | with 'MooseX::RW::Reader'; | ||
| 10 | |||
| 11 | |||
| 12 | has koha => ( is => 'rw', isa => 'Koha::Contrib::Sudoc::Koha', required => 1 ); | ||
| 13 | |||
| 14 | has select => ( | ||
| 15 | is => 'rw', | ||
| 16 | isa => 'Str', | ||
| 17 | default => 'SELECT biblionumber FROM biblio', | ||
| 18 | ); | ||
| 19 | |||
| 20 | has sth => ( | ||
| 21 | is => 'rw', | ||
| 22 | lazy => 1, | ||
| 23 | default => sub { | ||
| 24 | my $self = shift; | ||
| 25 | my $sth = $self->koha->dbh->prepare( $self->select ); | ||
| 26 | $sth->execute(); | ||
| 27 | $self->sth($sth); | ||
| 28 | }, | ||
| 29 | ); | ||
| 30 | |||
| 31 | has parser => ( | ||
| 32 | is => 'rw', | ||
| 33 | default => sub { MARC::Moose::Parser::Iso2709->new() } | ||
| 34 | ); | ||
| 35 | |||
| 36 | # Last returned record biblionumber; | ||
| 37 | has id => ( is => 'rw' ); | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | sub read { | ||
| 42 | my $self = shift; | ||
| 43 | |||
| 44 | while ( my ($id) = $self->sth->fetchrow ) { | ||
| 45 | if ( my $record = $self->get( $id ) ) { | ||
| 46 | $self->count($self->count + 1); | ||
| 47 | $self->id( $id ); | ||
| 48 | return $record; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | return 0; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | sub get { | ||
| 56 | my ($self, $id) = @_; | ||
| 57 | |||
| 58 | my $sth = $self->koha->dbh->prepare( | ||
| 59 | "SELECT marc FROM biblioitems WHERE biblionumber=? "); | ||
| 60 | $sth->execute( $id ); | ||
| 61 | my ($marc) = $sth->fetchrow; | ||
| 62 | my $record = $self->parser->parse($marc); | ||
| 63 | return $record; | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | no Moose; | ||
| 68 | __PACKAGE__->meta->make_immutable; | ||
| 69 | 1; | ||
| 70 | |||
| 71 | __END__ |