| 1 | package Biblio::COUNTER::Processor; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Biblio::COUNTER; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # A class designed to be inherited from for OO-style event handling | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 0 | my ($cls, %args) = @_; | |||||||||||||||||||||||||||
| 12 | 0 | my $self = bless { | |||||||||||||||||||||||||||
| 13 | 'ignore' => {}, | ||||||||||||||||||||||||||||
| 14 | %args, | ||||||||||||||||||||||||||||
| 15 | }, $cls; | ||||||||||||||||||||||||||||
| 16 | 0 | return $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub ignore { | ||||||||||||||||||||||||||
|
Subroutine
ignore: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($self, @what) = @_; | |||||||||||||||||||||||||||
| 21 | 0 | $self->{'ignore'}->{$_} = 1 for @what; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($self, $report) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | my $fh; | |||||||||||||||||||||||||||
| 27 | 0 | $self->{'file'} = $report; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (ref($report) eq '') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 29 | # Assume $report is a file name | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($report eq '-') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | $fh = \*STDIN; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | open $fh, '<', $report | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | or die "Can't open report '$report': $!"; | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 0 | $report = Biblio::COUNTER->report($fh); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | elsif ($report->isa('Biblio::COUNTER::Report')) { | ||||||||||||||||||||||||||||
| 40 | # Nothing special to do | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||
| 43 | # Assume it's a filehandle | ||||||||||||||||||||||||||||
| 44 | 0 | $report = Biblio::COUNTER->report($report); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 0 | $report->{'file'} = $self->{'file'}; | |||||||||||||||||||||||||||
| 47 | 0 | my $ignore = $self->{'ignore'}; | |||||||||||||||||||||||||||
| 48 | $report->{'callback'} = { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | '*' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 50 | 0 | my ($report, $callback_name, @args) = @_; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (!$ignore->{$callback_name} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ignore->{$callback_name} and defined(my $code = $self->can($callback_name))
MC/DC0%0/2
not $ignore->{$callback_name} and defined(my $code = $self->can($callback_name))
not $ignore->{$callback_name}
defined(my $code = $self->can($callback_name))
Truth table0%0/3
not(A) and B
A= not $ignore->{$callback_name}B= defined(my $code = $self->can($callback_name))
| |||||||||||||||||||||||||||||
| 52 | && defined(my $code = $self->can($callback_name))) { | ||||||||||||||||||||||||||||
| 53 | 0 | $code->($self, $report, @args); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||
| 56 | 0 | }; | |||||||||||||||||||||||||||
| 57 | 0 | $report->process; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | close $fh if defined $fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | return $report; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =pod | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | =head1 NAME | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | Biblio::COUNTER::Processor - superclass for Biblio::COUNTER processors | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Use | ||||||||||||||||||||||||||||
| 74 | use Biblio::COUNTER::Processor; | ||||||||||||||||||||||||||||
| 75 | $processor = Biblio::COUNTER::Processor->new; | ||||||||||||||||||||||||||||
| 76 | $processor->ignore(@events); | ||||||||||||||||||||||||||||
| 77 | $report = $processor->run; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Subclass | ||||||||||||||||||||||||||||
| 80 | use MyProcessor; | ||||||||||||||||||||||||||||
| 81 | @MyProcessor::ISA = qw(Biblio::COUNTER::Processor); | ||||||||||||||||||||||||||||
| 82 | # Event handlers | ||||||||||||||||||||||||||||
| 83 | sub begin_report { | ||||||||||||||||||||||||||||
| 84 | my ($self, $report) = @_; | ||||||||||||||||||||||||||||
| 85 | # etc. | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | sub count { | ||||||||||||||||||||||||||||
| 88 | my ($self, $report, $scope, $field, $period, $val) = @_; | ||||||||||||||||||||||||||||
| 89 | # etc. | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | # etc. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | B<Biblio::COUNTER::Processor> is an inheritable class that provides an | ||||||||||||||||||||||||||||
| 96 | intermediate interface to L<Biblio::COUNTER|Biblio::COUNTER>. When used on | ||||||||||||||||||||||||||||
| 97 | its own, it does nothing; subclasses must define handlers for the various | ||||||||||||||||||||||||||||
| 98 | events (e.g., C<begin_report> or C<count>) that are triggered as a report | ||||||||||||||||||||||||||||
| 99 | is processed. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Event-handling methods (if defined) are invoked with the arguments | ||||||||||||||||||||||||||||
| 102 | documented in L<Biblio::COUNTER>, except that an additional argument (the | ||||||||||||||||||||||||||||
| 103 | instance of the L<Biblio::COUNTER::Processor|Biblio::COUNTER::Processor> | ||||||||||||||||||||||||||||
| 104 | subclass) is prepended. | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | For a class that actually B<does> something when events are triggered, see | ||||||||||||||||||||||||||||
| 107 | L<Biblio::COUNTER::Processor::Simple|Biblio::COUNTER::Processor::Simple>. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 METHODS | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =over 4 | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item B<new> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | $processor = Biblio::COUNTER::Processor->new; | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Create a new processor. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =item B<run>(I<$file>) | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | $report = $processor->run($what); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Process the given report. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | I<$what> may be a file handle, the name of a file, or an instance of | ||||||||||||||||||||||||||||
| 126 | (a subclass of) L<Biblio::COUNTER::Report|Biblio::COUNTER::Report>. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | A L<Biblio::COUNTER::Report|Biblio::COUNTER::Report> object will be | ||||||||||||||||||||||||||||
| 129 | instantiated and its B<process> method invoked; each time an event is | ||||||||||||||||||||||||||||
| 130 | triggered, a method with the event's name (e.g., C<begin_record> or | ||||||||||||||||||||||||||||
| 131 | C<cant_fix>) is invoked B<if it is defined>. Since this class doesn't | ||||||||||||||||||||||||||||
| 132 | define any such methods, the default behavior when an event is triggered is | ||||||||||||||||||||||||||||
| 133 | to do nothing. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item B<ignore>(I<@events>) | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | $processor->ignore(qw/line input output/); | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Specify the events to ignore. The various events are documented in | ||||||||||||||||||||||||||||
| 140 | L<Biblio::COUNTER>. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =back | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =head1 INHERITANCE | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | B<Biblio::COUNTER::Processor> is designed to be inheritable; in fact, it | ||||||||||||||||||||||||||||
| 147 | doesn't do anything on its own (unless you count I<ignoring events> as | ||||||||||||||||||||||||||||
| 148 | doing something). | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 BUGS | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | There are no known bugs. Please report bugs to the author via e-mail | ||||||||||||||||||||||||||||
| 153 | (see below). | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | Paul Hoffman (nkuitse AT cpan DOT org) | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Copyright 2008 Paul M. Hoffman. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | This is free software, and is made available under the same terms as Perl | ||||||||||||||||||||||||||||
| 164 | itself. | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | L<Biblio::COUNTER> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | L<Biblio::COUNTER::Report> | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | L<Biblio::COUNTER::Report::Processor::Simple> | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||