COUNTER/Processor/Validate.pm

filter: Statementstmt 29.7% 11 / 37 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 7 totaltotal 18.9% 14 / 74 CC 11 SCAR 27.6
CC
11
Cov
19%
end_report
42.0
verbose
6.0
silent
6.0
CRAP 15.8
« COUNTER/Processor.pm ↑ Summary COUNTER/Processor/Simple.pm »
1 package Biblio::COUNTER::Processor::Validate;
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 # Validate processor -- just spits out a lot of lines to STDERR
9 # and prints [corrected] output to STDOUT
10  
11 1 @Biblio::COUNTER::Processor::Validate::ISA = qw(Biblio::COUNTER::Processor);
12  
13 0 ▶sub verbose { @_ > 1 ? $_[0]->{'verbose'} = $_[1] : $_[0]->{'verbose'} }
Subroutine verbose: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
14 0 ▶sub silent { @_ > 1 ? $_[0]->{'silent'} = $_[1] : $_[0]->{'silent'} }
Subroutine silent: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
15  
16 0 ▶sub output {
Subroutine output: not called CC=1 SCAR=6.9
Pod undocumented
17 0 my ($self, $report, $output) = @_;
18 0 print $output, "\n";
19 }
20  
21 0 ▶sub fixed {
Subroutine fixed: not called CC=2 SCAR=17.9
Pod undocumented
22 0 my ($self, $report, $field, $from, $to) = @_;
23 0 ▶ return unless $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
24 0 my $pos = $report->current_position;
25 0 print STDERR "warning ($pos): corrected $field from $from to $to\n";
26 }
27  
28 0 ▶sub cant_fix {
Subroutine cant_fix: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my ($self, $report, $field, $is, $expected) = @_;
30 0 ▶ return unless $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
31 0 my $pos = $report->current_position;
32 0 print STDERR "error ($pos): in $field, found $is expected $expected\n";
33 }
34  
35 0 ▶sub trimmed {
Subroutine trimmed: not called CC=2 SCAR=17.9
Pod undocumented
36 0 my ($self, $report, $field) = @_;
37 0 ▶ return unless $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->verbose 0 0 0
38 0 my $pos = $report->current_position;
39 0 print STDERR "warning ($pos): trimmed $field\n";
40 }
41  
42 0 ▶sub end_report {
Subroutine end_report: not called CC=6 SCAR=37.4
Pod undocumented
43 0 my ($self, $report) = @_;
44 0 my $errors = $report->{'errors'};
45 0 my $warnings = $report->{'warnings'};
46 0 ▶ unless ($self->silent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->silent) 0 0 0
47 0 print STDERR "$report->{'errors'} errors\n";
48 0 print STDERR "$report->{'warnings'} warnings\n";
49 }
50 0 ▶ print( ($errors + $warnings) ? "Report is not valid\n" : "Report is valid\n" )
Branch: 2 branches
BranchTrueFalseTotal
if $self->verbose 0 0 0
$errors + $warnings ? : 0 0 0
51 if $self->verbose;
52 0 ▶ exit 3 if $errors;
Branch: 1 branch
BranchTrueFalseTotal
if $errors 0 0 0
53 0 ▶ exit 2 if $warnings;
Branch: 1 branch
BranchTrueFalseTotal
if $warnings 0 0 0
54 0 exit 0;
55 }
56  
57  
58 1 1;
59  
60 =pod
61  
62 =head1 NAME
63  
64 Biblio::COUNTER::Processor::Validate - simple COUNTER report validator
65  
66 =head1 SYNOPSIS
67  
68 use Biblio::COUNTER::Processor::Validate;
69 $processor = Biblio::COUNTER::Processor::Validate->new;
70 $report = $processor->run;
71  
72 =head1 DESCRIPTION
73  
74 B<Biblio::COUNTER::Processor::Validate> processes a COUNTER report and prints
75 a verbose stream of data from the report to standard error, while printing
76 the report B<with corrections> to standard output.
77  
78 =head1 PUBLIC METHODS
79  
80 =over 4
81  
82 =item B<new>(I<%args>)
83  
84 $processor = Biblio::COUNTER::Processor::Validate->new;
85  
86 =item B<run>(I<$file>)
87  
88 $report = $processor->run($what);
89  
90 Process the given report.
91  
92 I<$what> may be a file handle, the name of a file, or an instance of
93 (a subclass of) L<Biblio::COUNTER::Report|Biblio::COUNTER::Report>.
94  
95 =item B<ignore>(I<@events>)
96  
97 $processor->ignore(qw/line input output/);
98  
99 Specify the events to ignore. The various events are documented in
100 L<Biblio::COUNTER>.
101  
102 =back
103  
104 =head1 INHERITANCE
105  
106 B<Biblio::COUNTER::Processor::Validate> is designed to be inheritable.
107  
108 =head1 BUGS
109  
110 There are no known bugs. Please report bugs to the author via e-mail
111 (see below).
112  
113 =head1 TO DO
114  
115 Document in detail the output that's produced.
116  
117 =head1 AUTHOR
118  
119 Paul Hoffman (nkuitse AT cpan DOT org)
120  
121 =head1 COPYRIGHT
122  
123 Copyright 2008-2009 Paul M. Hoffman.
124  
125 This is free software, and is made available under the same terms as Perl
126 itself.
127  
128 =head1 SEE ALSO
129  
130 L<Biblio::COUNTER>
131  
132 L<Biblio::COUNTER::Report>
133  
134 L<Biblio::COUNTER::Report::Processor>
135  
« COUNTER/Processor.pm ↑ Summary COUNTER/Processor/Simple.pm »