Biblio-COUNTER
view release on metacpan or search on metacpan
lib/Biblio/COUNTER.pm view on Meta::CPAN
I<%args> may contain any of the following:
=over 4
=item B<treat_blank_counts_as_zero>
If set to a true value, a blank cell where a count was expected is
treated as if it contained a zero; otherwise, blank counts are silently
ignored (the default).
=item B<change_not_available_to_blank>
If set to a true value (the default), the value C<n/a>) in a count
field will be changed to the empty string. It will B<never> be treated
as if it were zero, regardless of the B<treat_blank_counts_as_zero>
setting.
=item B<callback>
Get or set a reference to a hash of (I<$event>, I<$code>) pairs
specifying what to do for each of the events described under
lib/Biblio/COUNTER/Report.pm view on Meta::CPAN
my $rx_mon = qr/(?i)jan|feb|mar|apr|may|june?|july?|aug|sept?|oct|nov|dec|0[1-9]|1[0-2]/;
my $rx_year = qr/(?:2[012])?\d\d/; # Good through 2299
# ------------------------------------------------------------ PUBLIC METHODS --
sub new {
my ($cls, %args) = @_;
bless {
'treat_blank_counts_as_zero' => 0,
'change_not_available_to_blank' => 0,
'dont_reread_next_row' => 0,
%args,
}, $cls;
}
sub process {
my ($self) = @_;
$self->begin_file
->begin_report
->process_header
lib/Biblio/COUNTER/Report.pm view on Meta::CPAN
return $self;
}
sub _check_free_text_field {
my ($self, $field, $mode, $str) = @_;
if ($mode == EXACT_MATCH) {
$str = '' unless defined $str;
$self->_check_field($field, _exact_match_sub($str));
}
elsif ($mode == NOT_BLANK) {
$self->_check_field($field, \&_is_not_blank);
}
else {
$self->_check_field($field, \&_is_anything);
}
$self->_next;
}
sub _not_available {
my ($self) = @_;
if ($self->{'change_not_available_to_blank'}) {
$self->_fix('');
}
else {
$self->_cant_fix('<count>');
}
return $self;
}
sub _check_count {
my ($self, $field, $period) = @_;
lib/Biblio/COUNTER/Report.pm view on Meta::CPAN
$self->trigger_callback('count', $self->{'scope'}, $field, $period, $val);
}
}
elsif ($val eq '') {
if ($self->{'treat_blank_counts_as_zero'}) {
$container->{'count'}->{$normalized_period}->{$field} = $val;
$self->trigger_callback('count', $self->{'scope'}, $field, $period, 0);
}
}
elsif ($val =~ m{^n/a$}i) {
$self->_not_available;
}
else {
$self->_cant_fix('<count>');
}
}
else {
# YTD usage
if ($val =~ /^\d+$/) {
$container->{'count'}->{$field} = $val;
$self->trigger_callback("count_$field", $self->{'scope'}, $field, $val);
}
elsif ($val eq '') {
if ($self->{'treat_blank_counts_as_zero'}) {
$container->{'count'}->{$field} = $val;
$self->trigger_callback("count_$field", $self->{'scope'}, $field, 0);
}
}
elsif ($val =~ m{^n/a$}i) {
$self->_not_available;
}
else {
$self->_cant_fix('<count>');
}
}
$self->_next;
}
sub _exact_match_sub {
# Return a ref to code that compares the current cell's value to the given string
lib/Biblio/COUNTER/Report.pm view on Meta::CPAN
my ($self, $field, $cur) = @_;
if ($$cur =~ /^\d+$/) {
$self->_ok($cur);
}
else {
$self->_cant_fix('<count>');
}
return $self;
}
sub _is_not_blank {
my ($self, $field, $cur) = @_;
if ($$cur eq '') {
$self->_cant_fix('<not blank>');
return;
}
else {
$self->_ok($cur);
}
return $self;
}
( run in 2.006 seconds using v1.01-cache-2.11-cpan-0a987023a57 )