COUNTER/Processor/Atomize.pm

filter: Statementstmt 28.9% 11 / 38 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 3 totaltotal 22.2% 14 / 63 CC 9 SCAR 30.2
CC
9
Cov
21%
end_record
30.0
_default_callback
30.0
begin_report
2.0
CRAP 20.5
« COUNTER.pm ↑ Summary COUNTER/Processor.pm »
1 package Biblio::COUNTER::Processor::Atomize;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Biblio::COUNTER::Processor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 @Biblio::COUNTER::Processor::Atomize::ISA = qw(Biblio::COUNTER::Processor);
9  
10 0 ▶sub begin_report {
Subroutine begin_report: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my ($self, $report) = @_;
12 0 $self->{'number'} = 1;
13 }
14  
15 0 ▶sub end_report {
Subroutine end_report: not called CC=1 SCAR=6.9
Pod undocumented
16 0 my ($self, $report) = @_;
17 0 undef $self->{'number'};
18 }
19  
20 0 ▶sub end_record {
Subroutine end_record: not called CC=5 SCAR=34.0
Pod undocumented
21 0 my ($self, $report, $rec) = @_;
22 0 ▶ my $cb = $self->{'callback'} ||= \&_default_callback;
Condition0%0/2
$self->{"callback"} ||= \&Biblio::COUNTER::Processor::Atomize::_default_callback
l!l
00
MC/DC0%0/1
$self->{"callback"} ||= \&Biblio::COUNTER::Processor::Atomize::_default_callback
$self->{"callback"}
Truth table0%0/2
A
A= $self->{"callback"}
Aresult
11
00
23 0 my $count = delete $rec->{'count'};
24 0 foreach my $period (sort keys %$count) {
25 0 my $period_counts = $count->{$period};
26 0 ▶ if (ref $period_counts) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $period_counts) { } 0 0 0
27 0 ▶ while (my ($metric, $count) = each %$period_counts) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$period_counts) 0 0 0
28 $cb->(
29 'processor' => $self,
30 'report' => $report,
31 0 'recnum' => $self->{'number'}++,
32 %$rec,
33 'period' => $period,
34 'metric' => $metric,
35 'count' => $count,
36 );
37 }
38 }
39 else {
40 0 die "Huh?";
41 }
42 }
43 }
44  
45 0 ▶sub _default_callback {
Subroutine _default_callback: not called CC=5 SCAR=34.0
46 0 my %data = @_;
47 0 my $code = $data{'code'} = $data{'report'}->canonical_report_code;
48 0 $data{'file'} = $data{'processor'}->{'file'};
49 0 my @header = qw(Type File Platform Period Metric Count Title Publisher);
50 0 my @data = @data{qw(code file platform period metric count title publisher)};
51 0 ▶ if ($code =~ /^J/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code =~ /^J/) { } 0 0 0
elsif ($code =~ /^B/) { } 0 0 0
52 0 push @header, "Print ISSN", "Online ISSN";
53 0 push @data, @data{qw(print_issn online_issn)};
54 }
55 elsif ($code =~ /^B/) {
56 0 push @header, "ISBN";
57 0 push @data, @data{qw(isbn)};
58 }
59 0 ▶ if ($data{'recnum'} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data{"recnum"} == 1) 0 0 0
60 0 print join("\t", @header), "\n";
61 }
62 0 ▶ print join("\t", map { defined $_ ? $_ : '' } @data), "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
63 }
64  
65  
66 1 1;
67  
68 =pod
69  
70 =head1 NAME
71  
72 Biblio::COUNTER::Processor::Atomize - break a COUNTER report into itsy pieces
73  
74 =head1 SYNOPSIS
75  
76 use Biblio::COUNTER::Processor::Atomize;
77 $processor = Biblio::COUNTER::Processor::Atomize->new;
78 $report = $processor->run($file_or_filehandle);
79  
80 =head1 DESCRIPTION
81  
82 B<Biblio::COUNTER::Processor::Atomize> breaks a COUNTER report into
83 tiny pieces (figuratively speaking) and executes a callback for each
84 valid usage number it finds.
85  
86 The callback function should look something like this:
87  
88 sub my_callback {
89 my %data = @_;
90 $title = $data{title};
91 $count = $data{count};
92 $metric = $data{metric};
93 $period = $data{period};
94 # etc.
95 }
96  
97 The following elements may appear in the hash passed to the callback function:
98  
99 =over 4
100  
101 =item B<code>
102  
103 The short code that indicates the type of the report (e.g., C<JR1> or C<DB3>).
104  
105 =item B<file>
106  
107 The name of the file containing the report. Set to C<-> if processing
108 standard input.
109  
110 =item B<processor>
111  
112 The Biblio::COUNTER::Processor::Atomize instance.
113  
114 =item B<report>
115  
116 The instance of the appropriate subclass of Biblio::COUNTER::Report
117  
118 =item B<period>
119  
120 A string of the form I<YYYY-mm> denoting the period in question.
121  
122 =item B<metric>
123  
124 The type of event counted (C<requests>, C<sessions>, C<searches>, or
125 C<turnaways>).
126  
127 =item B<count>
128  
129 The count itself. The callback is B<not> executed for a blank or invalid count.
130  
131 =item B<platform>
132  
133 The platform on which the resource was provided.
134  
135 =item B<title>
136  
137 The resource title.
138  
139 =item B<publisher>
140  
141 The resource's publisher. May be the empty string.
142  
143 =item B<print_issn> (journal reports only)
144  
145 The journal's print ISSN.
146  
147 =item B<online_issn> (journal reports only)
148  
149 The journal's online ISSN.
150  
151 =item B<isbn> (book reports only)
152  
153 The book's ISBN.
154  
155 =back
156  
157 =head1 PUBLIC METHODS
158  
159 =over 4
160  
161 =item B<new>(I<%args>)
162  
163 $foo = Biblio::COUNTER::Processor::Atomize->new;
164  
165 I<%args> is a list of (key, value) pairs. The only key that means
166 anything is B<callback>; the value associated with it is a reference to
167 the desired callback function.
168  
169 The desired callback function prints (to standard output) a single
170 tab-delimited line for each datum, with a header. Each line of output has
171 the following elements, in the order listed:
172  
173 =over 4
174  
175 =item B<code>
176  
177 =item B<file>
178  
179 =item B<platform>
180  
181 =item B<period>
182  
183 =item B<metric>
184  
185 =item B<count>
186  
187 =item B<title>
188  
189 =item B<publisher>
190  
191 =item B<print_issn> (journal reports only)
192  
193 =item B<online_issn> (journal reports only)
194  
195 =item B<isbn> (book reports only)
196  
197 =back
198  
199 =item B<run>(I<$file>)
200  
201 $report = $processor->run($what);
202  
203 Process the given report.
204  
205 I<$what> may be a file handle, the name of a file, or an instance of
206 (a subclass of) L<Biblio::COUNTER::Report|Biblio::COUNTER::Report>.
207  
208 =back
209  
210 =head1 INHERITANCE
211  
212 B<Biblio::COUNTER::Processor::Atomize> is designed to be inheritable.
213  
214 =head1 BUGS
215  
216 There are no known bugs. Please report bugs to the author via e-mail
217 (see below).
218  
219 =head1 AUTHOR
220  
221 Paul Hoffman (nkuitse AT cpan DOT org)
222  
223 =head1 COPYRIGHT
224  
225 Copyright 2008 Paul M. Hoffman.
226  
227 This is free software, and is made available under the same terms as Perl
228 itself.
229  
230 =head1 SEE ALSO
231  
232 L<Biblio::COUNTER>
233  
234 L<Biblio::COUNTER::Report>
235  
236 L<Biblio::COUNTER::Report::Processor>
237  
« COUNTER.pm ↑ Summary COUNTER/Processor.pm »