File Coverage

blib/lib/Biblio/COUNTER/Processor/Validate.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 20 0.0
condition n/a
subroutine 3 10 30.0
pod 0 7 0.0
total 12 72 16.6


line stmt bran cond sub pod time code
1             package Biblio::COUNTER::Processor::Validate;
2              
3 1     1   11250 use warnings;
  1         3  
  1         67  
4 1     1   6 use strict;
  1         3  
  1         40  
5              
6 1     1   5 use Biblio::COUNTER::Processor;
  1         2  
  1         1519  
7              
8             # Validate processor -- just spits out a lot of lines to STDERR
9             # and prints [corrected] output to STDOUT
10              
11             @Biblio::COUNTER::Processor::Validate::ISA = qw(Biblio::COUNTER::Processor);
12              
13 0 0   0 0   sub verbose { @_ > 1 ? $_[0]->{'verbose'} = $_[1] : $_[0]->{'verbose'} }
14 0 0   0 0   sub silent { @_ > 1 ? $_[0]->{'silent'} = $_[1] : $_[0]->{'silent'} }
15              
16             sub output {
17 0     0 0   my ($self, $report, $output) = @_;
18 0           print $output, "\n";
19             }
20              
21             sub fixed {
22 0     0 0   my ($self, $report, $field, $from, $to) = @_;
23 0 0         return unless $self->verbose;
24 0           my $pos = $report->current_position;
25 0           print STDERR "warning ($pos): corrected $field from $from to $to\n";
26             }
27              
28             sub cant_fix {
29 0     0 0   my ($self, $report, $field, $is, $expected) = @_;
30 0 0         return unless $self->verbose;
31 0           my $pos = $report->current_position;
32 0           print STDERR "error ($pos): in $field, found $is expected $expected\n";
33             }
34              
35             sub trimmed {
36 0     0 0   my ($self, $report, $field) = @_;
37 0 0         return unless $self->verbose;
38 0           my $pos = $report->current_position;
39 0           print STDERR "warning ($pos): trimmed $field\n";
40             }
41              
42             sub end_report {
43 0     0 0   my ($self, $report) = @_;
44 0           my $errors = $report->{'errors'};
45 0           my $warnings = $report->{'warnings'};
46 0 0         unless ($self->silent) {
47 0           print STDERR "$report->{'errors'} errors\n";
48 0           print STDERR "$report->{'warnings'} warnings\n";
49             }
50 0 0         print( ($errors + $warnings) ? "Report is not valid\n" : "Report is valid\n" )
    0          
51             if $self->verbose;
52 0 0         exit 3 if $errors;
53 0 0         exit 2 if $warnings;
54 0           exit 0;
55             }
56              
57              
58             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 processes a COUNTER report and prints
75             a verbose stream of data from the report to standard error, while printing
76             the report B to standard output.
77              
78             =head1 PUBLIC METHODS
79              
80             =over 4
81              
82             =item B(I<%args>)
83              
84             $processor = Biblio::COUNTER::Processor::Validate->new;
85              
86             =item B(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.
94              
95             =item B(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.
101              
102             =back
103              
104             =head1 INHERITANCE
105              
106             B 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
131              
132             L
133              
134             L
135