ARK/Reader.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 6 Conditioncond n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 69 CC 4 SCAR 16.4
CC
4
Cov
0%
BUILD
12.0
read
6.0
percentage
2.0
CRAP 5.2
1 package Koha::Contrib::ARK::Reader;
2 $Koha::Contrib::ARK::Reader::VERSION = '1.0.3';
3 # ABSTRACT: Read Koha biblio records with/without ARK
4 use Moose;
5  
6 with 'MooseX::RW::Reader';
7  
8 use Moose::Util::TypeConstraints;
9 use Modern::Perl;
10 use C4::Context;
11 use C4::Biblio;
12 use MARC::Moose::Record;
13  
14  
15 has ark => ( is => 'rw', isa => 'Koha::Contrib::ARK' );
16  
17  
18 subtype 'BiblioSelect'
19 => as 'Str'
20 => where { $_ =~ /WithArk|WithoutArk|All/ }
21 => message { 'Invalid biblio selection' };
22  
23 has select => (
24 is => 'rw',
25 isa => 'BiblioSelect',
26 default => 'All',
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 sub percentage {
73 my $self = shift;
74 my $p = ($self->count * 100) / $self->total;
75 return sprintf("%.2f", $p);
76 }
77  
78 1;
79  
80 __END__
81  
82 =pod
83  
84 =encoding UTF-8
85  
86 =head1 NAME
87  
88 Koha::Contrib::ARK::Reader - Read Koha biblio records with/without ARK
89  
90 =head1 VERSION
91  
92 version 1.0.3
93  
94 =head1 ATTRIBUTES
95  
96 =head2 ark
97  
98 L<Koha::Contrib::ARK> object.
99  
100 =head2 select
101  
102 Selection of biblio records : All, WithArk, WithoutArk
103  
104 =head2 total
105  
106 Total of records to read
107  
108 =head1 AUTHOR
109  
110 Frédéric Demians <f.demians@tamil.fr>
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 This software is Copyright (c) 2018 by Fréderic Demians.
115  
116 This is free software, licensed under:
117  
118 The GNU General Public License, Version 3, June 2007
119  
120 =cut