line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Biblio::COUNTER::Processor::Atomize; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1070
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
2184
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
67
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Biblio::COUNTER::Processor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1663
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@Biblio::COUNTER::Processor::Atomize::ISA = qw(Biblio::COUNTER::Processor); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub begin_report { |
11
|
0
|
|
|
0
|
0
|
|
my ($self, $report) = @_; |
12
|
0
|
|
|
|
|
|
$self->{'number'} = 1; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub end_report { |
16
|
0
|
|
|
0
|
0
|
|
my ($self, $report) = @_; |
17
|
0
|
|
|
|
|
|
undef $self->{'number'}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub end_record { |
21
|
0
|
|
|
0
|
0
|
|
my ($self, $report, $rec) = @_; |
22
|
0
|
|
0
|
|
|
|
my $cb = $self->{'callback'} ||= \&_default_callback; |
23
|
0
|
|
|
|
|
|
my $count = delete $rec->{'count'}; |
24
|
0
|
|
|
|
|
|
foreach my $period (sort keys %$count) { |
25
|
0
|
|
|
|
|
|
my $period_counts = $count->{$period}; |
26
|
0
|
0
|
|
|
|
|
if (ref $period_counts) { |
27
|
0
|
|
|
|
|
|
while (my ($metric, $count) = each %$period_counts) { |
28
|
0
|
|
|
|
|
|
$cb->( |
29
|
|
|
|
|
|
|
'processor' => $self, |
30
|
|
|
|
|
|
|
'report' => $report, |
31
|
|
|
|
|
|
|
'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
|
|
|
|
|
|
|
sub _default_callback { |
46
|
0
|
|
|
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
|
0
|
|
|
|
|
if ($code =~ /^J/) { |
|
|
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
|
0
|
|
|
|
|
if ($data{'recnum'} == 1) { |
60
|
0
|
|
|
|
|
|
print join("\t", @header), "\n"; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
0
|
|
|
|
|
print join("\t", map { defined $_ ? $_ : '' } @data), "\n"; |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
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 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 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The short code that indicates the type of the report (e.g., C or C). |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item B |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
The name of the file containing the report. Set to C<-> if processing |
108
|
|
|
|
|
|
|
standard input. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item B |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The Biblio::COUNTER::Processor::Atomize instance. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item B |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
The instance of the appropriate subclass of Biblio::COUNTER::Report |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item B |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
A string of the form I denoting the period in question. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item B |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The type of event counted (C, C, C, or |
125
|
|
|
|
|
|
|
C). |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item B |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The count itself. The callback is B executed for a blank or invalid count. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item B |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
The platform on which the resource was provided. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item B |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
The resource title. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item B |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The resource's publisher. May be the empty string. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item B (journal reports only) |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
The journal's print ISSN. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item B (journal reports only) |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
The journal's online ISSN. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item B (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(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; 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 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item B |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item B |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item B |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item B |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item B |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item B |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item B |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item B (journal reports only) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item B (journal reports only) |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item B (book reports only) |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item B(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. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 INHERITANCE |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
B 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 |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
L |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
237
|
|
|
|
|
|
|
|