script/marcvalidate

filter: Statementstmt 87.7% 43 / 49 Branchbran 61.1% 11 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod n/a totaltotal 76.8% 63 / 82 CC 5 SCAR 9.9
CC
5
Cov
79%
print_error
5.3
__ANON__
2.0
usage
2.0
CRAP 2.7
« blib/lib/MARC/Schema.pm ↑ Summary Build »
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.01';
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 3 ▶use DDP;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 GetOptions(
15 'file|f=s' => \my $file,
16 'type|t=s' => \( my $type = 'RAW' ),
17 'schema|s=s' => \my $schema_file,
18 0 ▶ 'help|h' => sub { HelpMessage(0) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 3 ▶) or HelpMessage(1);
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(0); } ) or &HelpMessage(1) 0 3 3
20  
21 3 ▶$file = shift unless defined($file);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 2 1 3
22  
23 3 ▶usage() 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
24  
25 3 my $schema = MARC::Schema->new({file => $schema_file});
26  
27 3 my $parser;
28 3 ▶if ( $type eq 'RAW' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'RAW') { } 3 0 3
elsif ($type eq 'XML') { } 0 0 0
29 3 $parser = MARC::Parser::RAW->new($file);
30 }
31 elsif ( $type eq 'XML' ) {
32 0 $parser = MARC::Parser::XML->new($file);
33 }
34 else {
35 0 print qq{type '$type' not supported. Use 'RAW' or 'XML'};
36 }
37  
38 3 my $record_count = 0;
39 3 ▶while ( my $record = $parser->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $record = $parser->next) 30 3 33
40 30 $record_count++;
41 30 my @result = $schema->check($record);
42 30 ▶ if (@result > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result > 0) 3 27 30
43 3 print_error($record_count, \@result);
44 }
45 }
46  
47 sub print_error {
48 3 ▶ my ($record_count, $error) = @_;
Subroutine print_error: called CC=5 SCAR=16.7
49 3 foreach my $error (@{$error}) {
50 3 ▶ if ($error->{subfields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"subfields"}) 3 0 3
51 3 foreach my $subfield_code (keys %{$error->{subfields}}) {
52 3 print qq{$record_count\t$error->{tag}\t$error->{subfields}->{$subfield_code}->{message}\t$subfield_code\n};
53 }
54 }
55 3 ▶ if ($error->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"message"}) 0 3 3
56 0 print qq{$record_count\t$error->{tag}\t$error->{message}\n};
57 }
58 }
59 }
60  
61 sub usage {
62 0 ▶ print STDERR <<"EOF";
Subroutine usage: not called CC=1 SCAR=6.9
63 usage: $0 [options] file
64  
65 options:
66 --type,-t Type of MARC21 serialization (RAW|XML, default: RAW)
67 --schema,-s Location MARC JSON schema
68 --help Print this help
69 EOF
70 0 exit(1);
71 }
72  
73 =head1 NAME
74  
75 marcvalidate - Validate a file with MARC21 records
76  
77 =head1 SYNOPSIS
78  
79 $ marcvalidate [options] FILE
80  
81 options:
82 --type,-t Type of MARC21 serialization (RAW|XML, default: RAW)
83 --schema,-s Location MARC JSON schema
84 --help,-h Print this help
85  
86 =head1 AUTHOR
87  
88 Johann Rolschewski E<lt>jorol@cpan.orgE<gt>
89  
90 =head1 COPYRIGHT
91  
92 Copyright 2018- Johann Rolschewski
93  
94 =head1 LICENSE
95  
96 This library is free software; you can redistribute it and/or modify
97 it under the same terms as Perl itself.
98  
99 =cut
« blib/lib/MARC/Schema.pm ↑ Summary Build »