| 1 | package Biblio::COUNTER::Processor::Simple; | ||||||||||||||
| 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 | # Simple processor -- just spits out a lot of lines to STDERR | ||||||||||||||
| 9 | # and prints [corrected] output to STDOUT | ||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | @Biblio::COUNTER::Processor::Simple::ISA = qw(Biblio::COUNTER::Processor); | |||||||||||||
| 12 | |||||||||||||||
| 13 | 0 | ▶ | sub line { | ||||||||||||
|
Subroutine
line: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 14 | 0 | my ($self, $report, $line) = @_; | |||||||||||||
| 15 | 0 | print STDERR "LINE $line\n"; | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | sub input { | ||||||||||||
|
Subroutine
input: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 19 | 0 | my ($self, $report, $input) = @_; | |||||||||||||
| 20 | 0 | print STDERR "INPUT $input\n"; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | ▶ | sub begin_row { | ||||||||||||
|
Subroutine
begin_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 24 | 0 | my ($self, $report, $row) = @_; | |||||||||||||
| 25 | 0 | print STDERR "BEGIN row\n"; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 0 | ▶ | sub end_row { | ||||||||||||
|
Subroutine
end_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 29 | 0 | my ($self, $report, $row) = @_; | |||||||||||||
| 30 | 0 | print STDERR "END row\n"; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | |||||||||||||||
| 33 | 0 | ▶ | sub output { | ||||||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 34 | 0 | my ($self, $report, $output) = @_; | |||||||||||||
| 35 | 0 | print STDERR "OUTPUT $output\n"; | |||||||||||||
| 36 | 0 | print $output, "\n"; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | ▶ | sub ok { | ||||||||||||
|
Subroutine
ok: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 40 | 0 | my ($self, $report, $field, $val) = @_; | |||||||||||||
| 41 | 0 | my $pos = $report->current_position; | |||||||||||||
| 42 | 0 | ▶ | if ($field eq 'label') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub fixed { | ||||||||||||
|
Subroutine
fixed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 51 | 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 | 0 | ▶ | sub cant_fix { | ||||||||||||
|
Subroutine
cant_fix: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 57 | 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 | 0 | ▶ | sub trimmed { | ||||||||||||
|
Subroutine
trimmed: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 63 | 0 | my ($self, $report, $field) = @_; | |||||||||||||
| 64 | 0 | my $pos = $report->current_position; | |||||||||||||
| 65 | 0 | print STDERR "WARNING $pos TRIMMED $field\n"; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | ▶ | sub begin_file { | ||||||||||||
|
Subroutine
begin_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 69 | 0 | my ($self, $file) = @_; | |||||||||||||
| 70 | 0 | print STDERR "BEGIN file $file\n"; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 0 | ▶ | sub end_file { | ||||||||||||
|
Subroutine
end_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 74 | 0 | my ($self, $file) = @_; | |||||||||||||
| 75 | 0 | print STDERR "END file $file\n"; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | ▶ | sub begin_report { | ||||||||||||
|
Subroutine
begin_report: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 79 | 0 | my ($self, $report) = @_; | |||||||||||||
| 80 | 0 | print STDERR "BEGIN report\n"; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 0 | ▶ | sub end_report { | ||||||||||||
|
Subroutine
end_report: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 84 | 0 | my ($self, $report) = @_; | |||||||||||||
| 85 | 0 | print STDERR "BEGIN summary\n"; | |||||||||||||
| 86 | 0 | ▶ | if ($report->{'errors'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub begin_header { | ||||||||||||
|
Subroutine
begin_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 99 | 0 | my ($self, $report) = @_; | |||||||||||||
| 100 | 0 | print STDERR "BEGIN header\n"; | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 0 | ▶ | sub end_header { | ||||||||||||
|
Subroutine
end_header: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 104 | 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 | 0 | ▶ | sub begin_body { | ||||||||||||
|
Subroutine
begin_body: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 116 | 0 | my ($self, $report) = @_; | |||||||||||||
| 117 | 0 | print STDERR "BEGIN body\n"; | |||||||||||||
| 118 | } | ||||||||||||||
| 119 | |||||||||||||||
| 120 | 0 | ▶ | sub end_body { | ||||||||||||
|
Subroutine
end_body: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 121 | 0 | my ($self, $report) = @_; | |||||||||||||
| 122 | 0 | print STDERR "END body\n"; | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 0 | ▶ | sub begin_record { | ||||||||||||
|
Subroutine
begin_record: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 126 | 0 | my ($self, $report, $rec) = @_; | |||||||||||||
| 127 | 0 | print STDERR "BEGIN record\n"; | |||||||||||||
| 128 | } | ||||||||||||||
| 129 | |||||||||||||||
| 130 | 0 | ▶ | sub count { | ||||||||||||
|
Subroutine
count: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 131 | 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 | ▶ | if ($scope eq 'record') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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 | 0 | ▶ | sub end_record { | ||||||||||||
|
Subroutine
end_record: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||
| 144 | 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 | ▶ | if (ref $period_counts) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 151 | 0 | ▶ | while (my ($metric, $val) = each %$period_counts) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | 0 | ▶ | sub skip_blank_row { | ||||||||||||
|
Subroutine
skip_blank_row: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 164 | 0 | my ($self, $report) = @_; | |||||||||||||
| 165 | 0 | my $r = $report->{'r'}; | |||||||||||||
| 166 | 0 | print STDERR "SKIP $r blank\n"; | |||||||||||||
| 167 | } | ||||||||||||||
| 168 | |||||||||||||||
| 169 | |||||||||||||||
| 170 | 1 | 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<Biblio::COUNTER::Processor::Simple> processes a COUNTER report and prints | ||||||||||||||
| 188 | a verbose stream of data from the report to standard error, while printing | ||||||||||||||
| 189 | the report B<with corrections> to standard output. | ||||||||||||||
| 190 | |||||||||||||||
| 191 | =head1 PUBLIC METHODS | ||||||||||||||
| 192 | |||||||||||||||
| 193 | =over 4 | ||||||||||||||
| 194 | |||||||||||||||
| 195 | =item B<new>(I<%args>) | ||||||||||||||
| 196 | |||||||||||||||
| 197 | $foo = Biblio::COUNTER::Processor::Simple->new; | ||||||||||||||
| 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 | =item B<ignore>(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<Biblio::COUNTER>. | ||||||||||||||
| 214 | |||||||||||||||
| 215 | =back | ||||||||||||||
| 216 | |||||||||||||||
| 217 | =head1 INHERITANCE | ||||||||||||||
| 218 | |||||||||||||||
| 219 | B<Biblio::COUNTER::Processor::Simple> 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<Biblio::COUNTER> | ||||||||||||||
| 244 | |||||||||||||||
| 245 | L<Biblio::COUNTER::Report> | ||||||||||||||
| 246 | |||||||||||||||
| 247 | L<Biblio::COUNTER::Report::Processor> | ||||||||||||||
| 248 | |||||||||||||||