script/marcvalidate

filter: Statementstmt 71.7% 33 / 46 Branchbran 37.5% 6 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 61.8% 47 / 76 CC 5 SCAR 25.0
CC
5
Cov
62%
print_error
30.0
__ANON__
2.0
BEGIN
1.0
CRAP 12.2
↑ Summary blib/lib/MARC/Schema.pm »
1 #!/usr/bin/env perl
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 our $VERSION = '0.01';
7  
8 1 ▶use Getopt::Long 'HelpMessage';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MARC::Parser::RAW;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MARC::Parser::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use MARC::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶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 0 ▶ 'help|h' => sub { HelpMessage(0) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 1 ▶) or HelpMessage(1);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("file|f=s", \my $file, "type|t=s", \(my $type = "RAW"), "help|h", sub { &HelpMessage(0); } ) or &HelpMessage(1) 0 1 1
19  
20 1 ▶die "file not found" unless defined $file and -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file and -e $file 0 1 1
Condition33%1/3
defined $file and -e $file
!ll&&!rl&&r
001
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
21  
22 1 my $schema = MARC::Schema->new();
23  
24 1 my $parser;
25 1 ▶if ( $type eq 'RAW' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'RAW') { } 1 0 1
elsif ($type eq 'XML') { } 0 0 0
26 1 $parser = MARC::Parser::RAW->new($file);
27 }
28 elsif ( $type eq 'XML' ) {
29 0 $parser = MARC::Parser::XML->new($file);
30 }
31 else {
32 0 print qq{type '$type' not supported. Use 'RAW' or 'XML'};
33 }
34  
35 1 my $record_count = 0;
36 1 ▶while ( my $record = $parser->next() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $record = $parser->next) 10 1 11
37 10 $record_count++;
38 10 my @result = $schema->check($record);
39 10 ▶ if (@result > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result > 0) 0 10 10
40 0 print_error($record_count, \@result);
41 }
42 }
43  
44 sub print_error {
45 0 ▶ my ($record_count, $error) = @_;
Subroutine print_error: not called CC=5 SCAR=34.0
46 0 foreach my $error (@{$error}) {
47 0 ▶ if ($error->{subfields}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"subfields"}) 0 0 0
48 0 foreach my $subfield_code (keys %{$error->{subfields}}) {
49 0 print qq{$record_count\t$error->{tag}\t$error->{subfields}->{$subfield_code}->{message}\t$subfield_code\n};
50 }
51 }
52 0 ▶ if ($error->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{"message"}) 0 0 0
53 0 print qq{$record_count\t$error->{tag}\t$error->{message}\n};
54 }
55 }
56 }
57  
58 =head1 NAME
59  
60 marcvalidate - Validate a file with MARC21 records
61  
62 =head1 SYNOPSIS
63  
64 --file,-f Path to MARC21 file
65 --type,-t Type of MARC21 serialization (RAW|XML, default: RAW)
66 --help,-h Print this help
67  
68 =head1 AUTHOR
69  
70 Johann Rolschewski E<lt>jorol@cpan.orgE<gt>
71  
72 =head1 COPYRIGHT
73  
74 Copyright 2018- Johann Rolschewski
75  
76 =head1 LICENSE
77  
78 This library is free software; you can redistribute it and/or modify
79 it under the same terms as Perl itself.
80  
81 =cut
↑ Summary blib/lib/MARC/Schema.pm »