ARK/Reader.pm untested

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 6 Conditioncond n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 63 CC 4 SCAR 17.0
CC
4
Cov
0%
BUILD
12.0
read
6.0
BEGIN
2.0
CRAP 5.5
1 package Koha::Contrib::ARK::Reader;
2 # ABSTRACT: Read Koha biblio records with/without ARK
3 $Koha::Contrib::ARK::Reader::VERSION = '1.0.5';
4 use Moose;
5 use Moose::Util::TypeConstraints;
6 use Modern::Perl;
7 use C4::Context;
8 use C4::Biblio;
9 use MARC::Moose::Record;
10  
11 with 'MooseX::RW::Reader';
12  
13  
14 has ark => ( is => 'rw', isa => 'Koha::Contrib::ARK' );
15  
16  
17 subtype 'BiblioSelect'
18 => as 'Str'
19 => where { $_ =~ /WithArk|WithoutArk|All/ }
20 => message { 'Invalid biblio selection' };
21  
22 has select => (
23 is => 'rw',
24 isa => 'BiblioSelect',
25 default => 'All',
26 );
27  
28  
29 has total => ( is => 'rw', isa => 'Int', default => 0 );
30  
31  
32 has sth_bn => (is => 'rw');
33  
34  
35 sub BUILD {
36 my $self = shift;
37
38 my $dbh = C4::Context->dbh;
39 my $fromwhere = "FROM biblio_metadata";
40 $fromwhere .= " WHERE " .
41 $self->ark->field_query .
42 ($self->select eq 'WithoutArk' ? " =''" : " <> ''" )
43 if $self->select ne 'All';
44  
45 my $total = $dbh->selectall_arrayref("SELECT COUNT(*) $fromwhere");
46 $total = $total->[0][0];
47 $self->total( $total );
48  
49 my $sth = $dbh->prepare("SELECT biblionumber $fromwhere");
50 $sth->execute;
51 $self->sth_bn($sth);
52 }
53  
54  
55 sub read {
56 my $self = shift;
57  
58 my ($biblionumber) = $self->sth_bn->fetchrow();
59 return unless $biblionumber;
60  
61 $self->count( $self->count + 1 );
62  
63 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
64 $record = MARC::Moose::Record::new_from($record, 'Legacy');
65
66 $self->ark->set_current( $biblionumber, $record );
67  
68 return ($biblionumber, $record);
69 }
70  
71  
72 1;
73  
74 __END__
75  
76 =pod
77  
78 =encoding UTF-8
79  
80 =head1 NAME
81  
82 Koha::Contrib::ARK::Reader - Read Koha biblio records with/without ARK
83  
84 =head1 VERSION
85  
86 version 1.0.5
87  
88 =head1 ATTRIBUTES
89  
90 =head2 ark
91  
92 L<Koha::Contrib::ARK> object.
93  
94 =head2 select
95  
96 Selection of biblio records : All, WithArk, WithoutArk
97  
98 =head2 total
99  
100 Total of records to read
101  
102 =head1 AUTHOR
103  
104 Frédéric Demians <f.demians@tamil.fr>
105  
106 =head1 COPYRIGHT AND LICENSE
107  
108 This software is Copyright (c) 2020 by Fréderic Demians.
109  
110 This is free software, licensed under:
111  
112 The GNU General Public License, Version 3, June 2007
113  
114 =cut