File Coverage

blib/lib/Biblio/COUNTER/Processor/Simple.pm
Criterion Covered Total %
statement 9 87 10.3
branch 0 10 0.0
condition n/a
subroutine 3 24 12.5
pod 0 21 0.0
total 12 142 8.4


line stmt bran cond sub pod time code
1             package Biblio::COUNTER::Processor::Simple;
2              
3 1     1   2239 use warnings;
  1         2  
  1         38  
4 1     1   6 use strict;
  1         2  
  1         33  
5              
6 1     1   5 use Biblio::COUNTER::Processor;
  1         2  
  1         1636  
7              
8             # Simple processor -- just spits out a lot of lines to STDERR
9             # and prints [corrected] output to STDOUT
10              
11             @Biblio::COUNTER::Processor::Simple::ISA = qw(Biblio::COUNTER::Processor);
12              
13             sub line {
14 0     0 0   my ($self, $report, $line) = @_;
15 0           print STDERR "LINE $line\n";
16             }
17              
18             sub input {
19 0     0 0   my ($self, $report, $input) = @_;
20 0           print STDERR "INPUT $input\n";
21             }
22              
23             sub begin_row {
24 0     0 0   my ($self, $report, $row) = @_;
25 0           print STDERR "BEGIN row\n";
26             }
27              
28             sub end_row {
29 0     0 0   my ($self, $report, $row) = @_;
30 0           print STDERR "END row\n";
31             }
32              
33             sub output {
34 0     0 0   my ($self, $report, $output) = @_;
35 0           print STDERR "OUTPUT $output\n";
36 0           print $output, "\n";
37             }
38              
39             sub ok {
40 0     0 0   my ($self, $report, $field, $val) = @_;
41 0           my $pos = $report->current_position;
42 0 0         if ($field eq 'label') {
43 0           print STDERR "OK $pos LABEL $val\n";
44             }
45             else {
46 0           print STDERR "OK $pos FIELD $field IS $val\n";
47             }
48             }
49              
50             sub fixed {
51 0     0 0   my ($self, $report, $field, $from, $to) = @_;
52 0           my $pos = $report->current_position;
53 0           print STDERR "WARNING $pos CORRECTED $field FROM $from TO $to\n";
54             }
55              
56             sub cant_fix {
57 0     0 0   my ($self, $report, $field, $is, $expected) = @_;
58 0           my $pos = $report->current_position;
59 0           print STDERR "ERROR $pos IN $field FOUND $is EXPECTED $expected\n";
60             }
61              
62             sub trimmed {
63 0     0 0   my ($self, $report, $field) = @_;
64 0           my $pos = $report->current_position;
65 0           print STDERR "WARNING $pos TRIMMED $field\n";
66             }
67              
68             sub begin_file {
69 0     0 0   my ($self, $file) = @_;
70 0           print STDERR "BEGIN file $file\n";
71             }
72              
73             sub end_file {
74 0     0 0   my ($self, $file) = @_;
75 0           print STDERR "END file $file\n";
76             }
77              
78             sub begin_report {
79 0     0 0   my ($self, $report) = @_;
80 0           print STDERR "BEGIN report\n";
81             }
82              
83             sub end_report {
84 0     0 0   my ($self, $report) = @_;
85 0           print STDERR "BEGIN summary\n";
86 0 0         if ($report->{'errors'}) {
87 0           print STDERR "RESULT not valid\n";
88             }
89             else {
90 0           print STDERR "RESULT valid\n";
91             }
92 0           print STDERR "ERRORS $report->{'errors'}\n";
93 0           print STDERR "WARNINGS $report->{'warnings'}\n";
94 0           print STDERR "END summary\n";
95 0           print STDERR "END report\n";
96             }
97              
98             sub begin_header {
99 0     0 0   my ($self, $report) = @_;
100 0           print STDERR "BEGIN header\n";
101             }
102              
103             sub end_header {
104 0     0 0   my ($self, $report, $hdr) = @_;
105 0           my $periods = $report->{'periods'};
106 0           print STDERR "BEGIN metadata\n";
107 0           print STDERR "FIELD $_ $hdr->{$_}\n" for sort keys %$hdr;
108 0           foreach my $m (@$periods) {
109 0           print STDERR "PERIOD $m\n";
110             }
111 0           print STDERR "END metadata\n";
112 0           print STDERR "END header\n";
113             }
114              
115             sub begin_body {
116 0     0 0   my ($self, $report) = @_;
117 0           print STDERR "BEGIN body\n";
118             }
119              
120             sub end_body {
121 0     0 0   my ($self, $report) = @_;
122 0           print STDERR "END body\n";
123             }
124              
125             sub begin_record {
126 0     0 0   my ($self, $report, $rec) = @_;
127 0           print STDERR "BEGIN record\n";
128             }
129              
130             sub count {
131 0     0 0   my ($self, $report, $scope, $field, $period, $val) = @_;
132 0           my ($ok, $normalized_period);
133 0           ($ok, $period, $normalized_period) = $report->parse_period($period);
134 0           my $pos = $report->current_position;
135 0 0         if ($scope eq 'record') {
    0          
136 0           print STDERR "OK $pos COUNT $val METRIC $field PERIOD $normalized_period\n";
137             }
138             elsif ($scope eq 'report') {
139 0           print STDERR "OK $pos TOTAL $val METRIC $field PERIOD $normalized_period\n";
140             }
141             }
142              
143             sub end_record {
144 0     0 0   my ($self, $report, $rec) = @_;
145 0           print STDERR "BEGIN data\n";
146 0           my $count = delete $rec->{'count'};
147 0           print STDERR "FIELD $_ $rec->{$_}\n" for sort keys %$rec;
148 0           foreach my $m (sort keys %$count) {
149 0           my $period_counts = $count->{$m};
150 0 0         if (ref $period_counts) {
151 0           while (my ($metric, $val) = each %$period_counts) {
152 0           print STDERR "COUNT $val METRIC $metric PERIOD $m\n";
153             }
154             }
155             else {
156 0           print STDERR "COUNT $period_counts PERIOD $m\n";
157             }
158             }
159 0           print STDERR "END data\n";
160 0           print STDERR "END record\n";
161             }
162              
163             sub skip_blank_row {
164 0     0 0   my ($self, $report) = @_;
165 0           my $r = $report->{'r'};
166 0           print STDERR "SKIP $r blank\n";
167             }
168              
169              
170             1;
171              
172             =pod
173              
174             =head1 NAME
175              
176             Biblio::COUNTER::Processor::Simple - simple COUNTER report processor
177              
178             =head1 SYNOPSIS
179              
180             use Biblio::COUNTER::Processor::Simple;
181             $processor = Biblio::COUNTER::Processor::Simple->new;
182             $processor->ignore(@events);
183             $report = $processor->run;
184              
185             =head1 DESCRIPTION
186              
187             B processes a COUNTER report and prints
188             a verbose stream of data from the report to standard error, while printing
189             the report B to standard output.
190              
191             =head1 PUBLIC METHODS
192              
193             =over 4
194              
195             =item B(I<%args>)
196              
197             $foo = Biblio::COUNTER::Processor::Simple->new;
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             =item B(I<@events>)
209              
210             $processor->ignore(qw/line input output/);
211              
212             Specify the events to ignore. The various events are documented in
213             L.
214              
215             =back
216              
217             =head1 INHERITANCE
218              
219             B is designed to be inheritable.
220              
221             =head1 BUGS
222              
223             There are no known bugs. Please report bugs to the author via e-mail
224             (see below).
225              
226             =head1 TO DO
227              
228             Document in detail the output that's produced.
229              
230             =head1 AUTHOR
231              
232             Paul Hoffman (nkuitse AT cpan DOT org)
233              
234             =head1 COPYRIGHT
235              
236             Copyright 2008 Paul M. Hoffman.
237              
238             This is free software, and is made available under the same terms as Perl
239             itself.
240              
241             =head1 SEE ALSO
242              
243             L
244              
245             L
246              
247             L
248