| 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
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | $file = shift unless defined($file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | usage() unless defined $file and -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $file and -e $file
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 40 | 30 | $record_count++; | |||||||||||||||||||||||||||
| 41 | 30 | my @result = $schema->check($record); | |||||||||||||||||||||||||||
| 42 | 30 | ▶ | if (@result > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||