File Coverage

blib/lib/App/MARC/Count.pm
Criterion Covered Total %
statement 48 51 94.1
branch 5 8 62.5
condition 4 6 66.6
subroutine 9 9 100.0
pod 2 2 100.0
total 68 76 89.4


line stmt bran cond sub pod time code
1             package App::MARC::Count;
2              
3 4     4   95015 use strict;
  4         25  
  4         96  
4 4     4   19 use warnings;
  4         9  
  4         104  
5              
6 4     4   1769 use Class::Utils qw(set_params);
  4         113390  
  4         75  
7 4     4   261 use English;
  4         7  
  4         28  
8 4     4   8979 use Getopt::Std;
  4         248  
  4         254  
9 4     4   1905 use MARC::File::XML (BinaryEncoding => 'utf8', RecordFormat => 'MARC21');
  4         457833  
  4         110  
10 4     4   2195 use Unicode::UTF8 qw(encode_utf8);
  4         1911  
  4         1468  
11              
12             our $VERSION = 0.01;
13              
14             # Constructor.
15             sub new {
16 5     5 1 5251 my ($class, @params) = @_;
17              
18             # Create object.
19 5         12 my $self = bless {}, $class;
20              
21             # Process parameters.
22 5         25 set_params($self, @params);
23              
24             # Object.
25 4         34 return $self;
26             }
27              
28             # Run.
29             sub run {
30 3     3 1 4 my $self = shift;
31              
32             # Process arguments.
33 3         11 $self->{'_opts'} = {
34             'h' => 0,
35             };
36 3 100 66     11 if (! getopts('h', $self->{'_opts'}) || @ARGV < 1
      66        
37             || $self->{'_opts'}->{'h'}) {
38              
39 2         160 print STDERR "Usage: $0 [-h] [--version] marc_xml_file\n";
40 2         24 print STDERR "\t-h\t\tPrint help.\n";
41 2         20 print STDERR "\t--version\tPrint version.\n";
42 2         19 print STDERR "\tmarc_xml_file\tMARC XML file.\n";
43 2         10 return 1;
44             }
45 1         31 $self->{'_marc_xml_file'} = shift @ARGV;
46              
47 1         12 my $marc_file = MARC::File::XML->in($self->{'_marc_xml_file'});
48 1         103 my $ret_hr = {};
49 1         3 my $num = 1;
50 1         2 my $previous_record;
51 1         3 while (1) {
52 3         4 my $record = eval {
53 3         11 $marc_file->next;
54             };
55 3 50       6528 if ($EVAL_ERROR) {
56 0 0       0 print STDERR "Cannot process '$num' record. ".
57             (
58             defined $previous_record
59             ? "Previous record is ".encode_utf8($previous_record->title)."\n"
60             : ''
61             );
62 0         0 print STDERR "Error: $EVAL_ERROR\n";
63 0         0 next;
64             }
65 3 100       7 if (! defined $record) {
66 1         2 last;
67             }
68 2         23 $previous_record = $record;
69              
70 2         4 $num++;
71             }
72              
73             # Print out.
74 1         43 print $num."\n";
75            
76 1         29 return 0;
77             }
78              
79             1;
80              
81              
82             __END__