script/marcvalidate

filter: Statementstmt 91.1% 41 / 45 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod n/a totaltotal 78.9% 60 / 76 CC 2 SCAR 2.9
CC
2
Cov
80%
_id
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/MARC/Schema.pm ↑ Summary
1 #!/usr/bin/env perl
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.10';
7  
8 3 ▶use Getopt::Long 'HelpMessage';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use MARC::Parser::RAW;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use MARC::Parser::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use MARC::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 GetOptions(
14 'file|f=s' => \my $file,
15 'type|t=s' => \( my $type = 'RAW' ),
16 'schema|s=s' => \my $schema_file,
17 0 ▶ 'help|h' => sub { HelpMessage() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 3 ▶) or HelpMessage();
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("file|f=s", \my $file, "type|t=s", \(my $type = "RAW"), "schema|s=s", \my $schema_file, "help|h", sub { &HelpMessage(); } ) or &HelpMessage() 3 0 3
19  
20 3 ▶$file = shift unless defined($file);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 2 1 3
21  
22 3 ▶HelpMessage() unless defined $file and -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and -e $file 0 3 3
Condition33%1/3
defined $file and -e $file
!ll&&!rl&&r
003
MC/DC0%0/2
defined $file and -e $file
defined $file -e $file
Truth table33%1/3
A and B
A= defined $fileB= -e $file
ABresult
0X0
100
111
23  
24 3 my $schema = MARC::Schema->new({file => $schema_file});
25  
26 3 my $parser;
27 3 ▶if ( $type eq 'RAW' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'RAW') { } 3 0 3
elsif ($type eq 'XML') { } 0 0 0
28 3 $parser = MARC::Parser::RAW->new($file);
29 }
30 elsif ( $type eq 'XML' ) {
31 0 $parser = MARC::Parser::XML->new($file);
32 }
33 else {
34 0 print q{type '$type' not supported. Use 'RAW' or 'XML'};
35 }
36  
37 3 my $record_count = 0;
38 3 ▶while ( my $record = $parser->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $record = $parser->next) 30 3 33
39 30 $record_count++;
40 30 my $id = _id($record);
41 30 my @error = $schema->check($record);
42 30 ▶ if (@error > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@error > 0) 3 27 30
43 3 foreach my $error (@error) {
44 3 ▶ if (exists $error->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $error->{'value'}) { } 3 0 3
45 3 print qq{$id\t$error->{tag}\t$error->{error}\t$error->{value}\n};
46 } else {
47 0 print qq{$id\t$error->{tag}\t$error->{error}\t\n};
48 }
49 }
50 }
51 }
52  
53 30 ▶sub _id {
Subroutine _id: called CC=2 SCAR=7.0
54 30 my ($record) = @_;
55 30 my ($id) = map { $_->[-1] } grep { $_->[0] eq '001' } @$record;
56 30 ▶ $id = defined $id ? $id : $record_count;
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 30 0 30
57 30 return $id;
58 }
59  
60 __END__
« blib/lib/MARC/Schema.pm ↑ Summary