| 1 | package App::picadata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '2.09'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray :config bundling); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use PICA::Data qw(pica_parser pica_writer pica_annotation); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use PICA::Patch qw(pica_diff pica_patch); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use PICA::Schema qw(field_identifier); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use PICA::Schema::Builder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Getopt::Long qw(:config bundling); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use List::Util qw(any all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Text::Abbrev; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my %TYPES = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | bin => 'Binary', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | dat => 'Binary', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | binary => 'Binary', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | extpp => 'Binary', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ext => 'Binary', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | plain => 'Plain', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | pp => 'Plain', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | import => 'Import', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | plus => 'Plus', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | norm => 'Plus', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | normpp => 'Plus', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | xml => 'XML', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ppxml => 'PPXML', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | pixml => 'PIXML', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | json => 'JSON', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ndjson => 'JSON', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my %COLORS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | tag => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | occurrence => 'magenta', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | code => 'red', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | value => 'green' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | my ($class, @argv) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=54 SCAR=59.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | my $terminal = -t *STDIN; ## no critic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | my $command = (!@argv && $terminal) ? 'help' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @argv and $terminal
MC/DC0%0/2
not @argv and $terminal
not @argv
$terminal
Truth table33%1/3
not(A) and B
A= not @argvB= $terminal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | my $number = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | if (my ($i) = grep {$argv[$_] =~ /^-(\d+)$/} (0 .. @argv - 1)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | $number = -(splice @argv, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | my $noAnnotate = grep {$_ eq '-A'} @argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | my @path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my $opt = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | number => \$number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | help => sub {$command = 'help'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | version => sub {$command = 'version'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | build => sub {$command = 'build'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | count => sub {$command = 'count'}, # for backwards compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | path => \@path, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | modify => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | my %cmd = abbrev | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | qw(convert get count levels fields filter subfields sf explain validate build diff patch help version modify join); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | if ($cmd{$argv[0]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $command = $cmd{shift @argv}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $command =~ s/^sf$/subfields/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | GetOptionsFromArray( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | \@argv, $opt, 'from|f=s', 'to|t:s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 'schema|s=s', 'annotate|A|a', 'abbrev|B', 'build|b', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 'unknown|u!', 'count|c', 'order|o', 'path|p=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 'level|l:i', 'number|n:i', 'color|C', 'mono|M', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'help|h|?', 'version|V', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ) or pod2usage(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | $opt->{number} = $number; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | $opt->{annotate} = 0 if $noAnnotate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | $opt->{color} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | ▶ | = !$opt->{mono} && ($opt->{color} || -t *STDOUT); ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
!$opt->{'mono'} && ($opt->{'color'} || -t *STDOUT)
$opt->{"color"} or -t *STDOUT
MC/DC0%0/3
!$opt->{'mono'} && ($opt->{'color'} || -t *STDOUT)
!$opt->{'mono'}
$opt->{"color"}
-t *STDOUT
Truth table25%1/4
not(A) && B or C
A= !$opt->{'mono'}B= $opt->{"color"}C= -t *STDOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 6 | delete $opt->{$_} for qw(count build help version); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 6 | ▶ | if ($command eq 'modify') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | die "missing path argument!\n" unless @argv; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | push @{$opt->{modify}}, parse_path(shift @argv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $value = shift @argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | die "missing value argument!\n" unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | utf8::decode($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | push @{$opt->{modify}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | my $pattern = '[012.][0-9.][0-9.][A-Z@.](\$[^|]+|/[0-9.-]+)?'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | while (@argv && $argv[0] =~ /^$pattern(\s*\|\s*($pattern)?)*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@argv and $argv[0] =~ /^$pattern(\s*\|\s*($pattern)?)*$/u
MC/DC100%2/2
@argv and $argv[0] =~ /^$pattern(\s*\|\s*($pattern)?)*$/u
@argv
$argv[0] =~ /^$pattern(\s*\|\s*($pattern)?)*$/u
Truth table100%3/3
A and B
A= @argvB= $argv[0] =~ /^$pattern(\s*\|\s*($pattern)?)*$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | push @path, shift @argv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | @path = map {parse_path($_)} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | grep {$_ ne ""} map {split /\s*[\|,]\s*/, $_} @path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | ▶ | if (@path && all {$_->subfields ne ""} @path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
@path and &all(sub {
$_->subfields ne "";
}
, @path)
MC/DC100%2/2
@path and &all(sub {
$_->subfields ne "";
}
, @path)
@path
&all(sub {
$_->subfields ne "";
}
, @path)
Truth table100%3/3
A and B
A= @pathB= &all(sub {
$_->subfields ne "";
}
, @path)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | ▶ | $command = 'get' unless $command; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | $opt->{order} = 1 if $command =~ /(diff|patch|levels)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | ▶ | unless ($command) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if ($opt->{schema} && !$opt->{annotate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$opt->{"schema"} and not $opt->{"annotate"}
MC/DC0%0/2
$opt->{"schema"} and not $opt->{"annotate"}
$opt->{"schema"}
not $opt->{"annotate"}
Truth table33%1/3
A and not(B)
A= $opt->{"schema"}B= not $opt->{"annotate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $command = 'validate'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | elsif ($opt->{abbrev}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $command = 'build'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | $command = 'convert'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | if ($command =~ /validate|explain|fields|subfields/ && !$opt->{schema}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$command =~ /validate|explain|fields|subfields/u and not $opt->{"schema"}
MC/DC0%0/2
$command =~ /validate|explain|fields|subfields/u and not $opt->{"schema"}
$command =~ /validate|explain|fields|subfields/u
not $opt->{"schema"}
Truth table33%1/3
A and not(B)
A= $command =~ /validate|explain|fields|subfields/uB= not $opt->{"schema"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($ENV{PICA_SCHEMA}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $opt->{schema} = $ENV{PICA_SCHEMA}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | elsif ($command =~ /validate|explain/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $opt->{error} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | = "$command requires an Avram Schema (via option -s or environment variable PICA_SCHEMA)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | $opt->{annotate} = 1 if $command eq 'diff'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | ▶ | $opt->{annotate} = 0 if $command eq 'patch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | if ($opt->{schema}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $opt->{schema} = load_schema($opt->{schema}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $opt->{schema}{ignore_unknown} = $opt->{unknown}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if ($command eq 'explain' && !@path && !@argv && $terminal) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$command eq "explain" and not @path and not @argv and $terminal
$command eq "explain" and not @path and not @argv
$command eq "explain" and not @path
MC/DC0%0/4
$command eq "explain" and not @path and not @argv and $terminal
$command eq "explain"
not @path
not @argv
$terminal
Truth table0%0/5
A and not(B) and not(C) and D
A= $command eq "explain"B= not @pathC= not @argvD= $terminal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | while (my ($id, $field) = each %{$opt->{schema}{fields} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | push @path, parse_path($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # see <https://github.com/gbv/k10plus-avram-api/issues/12> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | my $sf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | = ref $field->{subfields} eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ? $field->{subfields} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | push @path, map {parse_path("$id\$$_")} keys %$sf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # all path expressions have been initialized as PICA::Path objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | $opt->{path} = \@path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | if ($command =~ qr{diff|patch}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | unshift @argv, '-' if @argv == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $opt->{error} = "$command requires two input files" if @argv != 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ($command eq 'diff') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # only Plain and JSON support annotations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $opt->{to} = 'plain' unless $TYPES{lc $opt->{to}} eq 'JSON'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | ▶ | $opt->{input} = @argv ? \@argv : ['-']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | ▶ | if (my $name = $opt->{from}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | $opt->{from} = $TYPES{lc $opt->{from}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | or $opt->{error} = "unknown serialization type: $name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # default output format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 6 | ▶ | unless ($opt->{to}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | ▶ | if ($command =~ /(convert|levels|filter|diff|patch|modify|join)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | $opt->{to} = $opt->{from}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | $opt->{to} ||= $TYPES{lc $1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | ▶ | if $opt->{input}->[0] =~ /\.([a-z]+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"to"} ||= $TYPES{lc $1}
MC/DC0%0/2
$opt->{"to"} ||= $TYPES{lc $1}
$opt->{"to"}
$TYPES{lc $1}
Truth table33%1/3
A ||= B
A= $opt->{"to"}B= $TYPES{lc $1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | $opt->{to} ||= 'plain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt->{"to"} ||= "plain"
MC/DC100%1/1
$opt->{"to"} ||= "plain"
$opt->{"to"}
Truth table100%2/2
A
A= $opt->{"to"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ▶ | elsif ($command eq 'validate' && $opt->{annotate}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$command eq "validate" and $opt->{"annotate"}
MC/DC0%0/2
$command eq "validate" and $opt->{"annotate"}
$command eq "validate"
$opt->{"annotate"}
Truth table33%1/3
A and B
A= $command eq "validate"B= $opt->{"annotate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $opt->{to} = 'plain'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | ▶ | if (my $name = $opt->{to}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | $opt->{to} = $TYPES{lc $opt->{to}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | ▶ | or $opt->{error} = "unknown serialization type: $name"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | $opt->{command} = $command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | bless $opt, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | sub parser_from_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my ($self, $in, $format) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parser_from_input: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ($in eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $in = *STDIN; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | binmode $in, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | die "File not found: $in\n" unless -e $in; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $format ||= $self->{from}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format ||= $self->{"from"}
MC/DC0%0/2
$format ||= $self->{"from"}
$format
$self->{"from"}
Truth table0%0/3
A ||= B
A= $formatB= $self->{"from"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $format ||= $TYPES{lc $1} if $in =~ /\.([a-z]+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$format ||= $TYPES{lc $1}
MC/DC0%0/2
$format ||= $TYPES{lc $1}
$format
$TYPES{lc $1}
Truth table0%0/3
A ||= B
A= $formatB= $TYPES{lc $1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | return pica_parser($format || 'plain', $in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$format || 'plain'
MC/DC0%0/1
$format || 'plain'
$format
Truth table0%0/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub load_schema { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my ($schema) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_schema: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($schema =~ qr{^https?://}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | require HTTP::Tiny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $res = HTTP::Tiny->new->get($schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | die "HTTP request failed: $schema\n" unless $res->{success}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $json = $res->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | open(my $fh, "<", $schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | or die "Failed to open schema file: $schema\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $json = join "\n", <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | return PICA::Schema->new(JSON::PP->new->decode($json)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=53 SCAR=79.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $command = $self->{command}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $schema = $self->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | my @pathes = @{$self->{path} || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # commands that don't parse any input data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($self->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | pod2usage($self->{error}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | elsif ($command eq 'help') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | pod2usage( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | -verbose => 99, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | -sections => "SYNOPSIS|COMMANDS|OPTIONS|DESCRIPTION|EXAMPLES" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | elsif ($command eq 'version') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | say $PICA::Data::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | elsif ($command eq 'explain') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->explain($schema, $_) for @pathes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | unless (@pathes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | while (<STDIN>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if ($_ =~ /^([^0-9a-z]\s+)?([^ ]+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $path = eval {parse_path($_)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ($path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->explain($schema, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | warn "invalid PICA Path: $_\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # initialize writer and schema builder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $writer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if ($self->{to}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | $writer = pica_writer( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $self->{to}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | color => ($self->{color} ? \%COLORS : undef), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | schema => $schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | annotate => $self->{annotate}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | binmode *STDOUT, ':encoding(UTF-8)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | my $builder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | = $command =~ /(build|fields|subfields|explain)/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | ? PICA::Schema::Builder->new($schema ? %$schema : ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | my $joined = $command eq 'join' ? PICA::Data->new : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # additional options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $number = $self->{number}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my $level = $self->{level}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $stats = {records => 0, holdings => 0, items => 0, fields => 0}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $invalid = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my @getFields = grep {$_->subfields eq ""} @pathes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | my @getSubfields = grep {$_->subfields ne ""} @pathes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | my $process = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | my $record = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=26 SCAR=65.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ($command eq 'get' && @getSubfields) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command eq "get" and @getSubfields
MC/DC0%0/2
$command eq "get" and @getSubfields
$command eq "get"
@getSubfields
Truth table0%0/3
A and B
A= $command eq "get"B= @getSubfields
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | say $_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | for map {@{$record->match($_, split => 1) // []}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$record->match($_, "split", 1) // []
MC/DC0%0/1
$record->match($_, "split", 1) // []
$record->match($_, "split", 1)
Truth table0%0/2
A
A= $record->match($_, "split", 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | @getSubfields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $record = $record->sort if $self->{order}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | if ($command eq 'filter' && @pathes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$command eq "filter" and @pathes
MC/DC0%0/2
$command eq "filter" and @pathes
$command eq "filter"
@pathes
Truth table0%0/3
A and B
A= $command eq "filter"B= @pathes
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | my @values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | = map {@{$record->match($_, split => 1) // []}} @pathes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$record->match($_, "split", 1) // []
MC/DC0%0/1
$record->match($_, "split", 1) // []
$record->match($_, "split", 1)
Truth table0%0/2
A
A= $record->match($_, "split", 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | return unless @values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # reduce record to selected fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $record->{record} = $record->fields(@getFields) if @getFields; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | return if $record->empty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ($command eq 'modify') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ($self->{annotate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # can't annotate an already annoted record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | pica_annotation($_, undef) for @{$record->{record}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $before = [map {[@$_]} @{$record->{record}}]; # deep copy | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my @modify = @{$self->{modify}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | while (@modify) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $path = shift @modify; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $value = shift @modify; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $record->update($path, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ($self->{annotate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $record = pica_diff($before, $record, keep => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # TODO: also validate on other commands? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ($command eq 'validate') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | my @errors = $schema->check( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $record, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | ignore_unknown => !$self->{unknown}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | annotate => $self->{annotate} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if (@errors) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | unless ($self->{annotate}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | say(defined $record->{_id} ? $record->{_id} . ": $_" : $_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | for @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $invalid++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($joined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | push @{$joined->{record}}, @{$record->{record}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | elsif ($writer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $writer->write($record); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | $builder->add($record) if $builder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if ($command eq 'count') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | $stats->{holdings} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | += grep {@{$_->fields('1...')}} @{$record->holdings}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $stats->{items} += grep {!$_->empty} @{$record->items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $stats->{fields} += @{$record->{record}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $stats->{records}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ($command eq 'diff') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my @parser = map {$self->parser_from_input($_)} @{$self->{input}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $a = $parser[0]->next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $b = $parser[1]->next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | if ($a or $b) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a or $b
MC/DC0%0/2
$a or $b
$a
$b
Truth table0%0/3
A or B
A= $aB= $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | $writer->write(pica_diff($a || [], $b || [])); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$a || []
$b || []
MC/DC0%0/1
$a || []
$a
MC/DC0%0/1
$b || []
$b
Truth table0%0/2
A
A= $a
Truth table0%0/2
A
A= $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | last if $number && $number <= ++$stats->{record}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$number and $number <= ++$stats->{"record"}
MC/DC0%0/2
$number and $number <= ++$stats->{"record"}
$number
$number <= ++$stats->{"record"}
Truth table0%0/3
A and B
A= $numberB= $number <= ++$stats->{"record"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | elsif ($command eq 'patch') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $parser = $self->parser_from_input($self->{input}[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # TODO: allow to read diff in PICA/JSON | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $patches = $self->parser_from_input($self->{input}[1], 'plain'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $diff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | while (my $record = $parser->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | $diff = $patches->next || $diff; # keep latest diff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$patches->next || $diff
MC/DC0%0/2
$patches->next || $diff
$patches->next
$diff
Truth table0%0/3
A || B
A= $patches->nextB= $diff
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | die "Missing patch to apply in $self->{input}[1]\n" unless $diff; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $changed = eval {pica_patch($record, $diff)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | if (!$changed || $@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $changed or $@
MC/DC0%0/2
not $changed or $@
not $changed
$@
Truth table0%0/3
not(A) or B
A= not $changedB= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | warn $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | $writer->write($changed || []); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$changed || []
MC/DC0%0/1
$changed || []
$changed
Truth table0%0/2
A
A= $changed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | last if $number && $number <= ++$stats->{record}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$number and $number <= ++$stats->{"record"}
MC/DC0%0/2
$number and $number <= ++$stats->{"record"}
$number
$number <= ++$stats->{"record"}
Truth table0%0/3
A and B
A= $numberB= $number <= ++$stats->{"record"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | my $split = $command eq 'levels' || ($level // -1) >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$command eq 'levels' || ($level // -1) >= 0
$level // -1
MC/DC0%0/2
$command eq 'levels' || ($level // -1) >= 0
$command eq 'levels'
$level
Truth table0%0/3
A || B
A= $command eq 'levels'B= $level
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | RECORD: foreach my $in (@{$self->{input}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $parser = $self->parser_from_input($in); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | while (my $next = $parser->next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | for ($split ? $next->split($level) : $next) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $process->($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | last RECORD if $number and $stats->{records} >= $number; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$number and $stats->{"records"} >= $number
MC/DC0%0/2
$number and $stats->{"records"} >= $number
$number
$stats->{"records"} >= $number
Truth table0%0/3
A and B
A= $numberB= $stats->{"records"} >= $number
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if ($writer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | $writer->write($joined->sort) if $joined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $writer->end(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if ($command eq 'count') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | $stats->{invalid} = $invalid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | say $stats->{$_} . " $_" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | for grep {$stats->{$_}} qw(records invalid holdings items fields); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | elsif ($command =~ /(sub)?fields/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $fields = $builder->schema->{fields}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | for my $id (sort keys %$fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ($command eq 'fields') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $self->document($id, $self->{abbrev} ? 0 : $fields->{$id}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | my $sfs = $fields->{$id}->{subfields} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$fields->{$id}{'subfields'} || {}
MC/DC0%0/1
$fields->{$id}{'subfields'} || {}
$fields->{$id}{'subfields'}
Truth table0%0/2
A
A= $fields->{$id}{'subfields'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | for (keys %$sfs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | $self->document("$id\$$_", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $self->{abbrev} ? 0 : $sfs->{$_}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | elsif ($command eq 'build') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $schema = $builder->schema; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | print JSON::PP->new->indent->space_after->canonical->convert_blessed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | ->encode($self->{abbrev} ? $schema->abbreviated : $schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | exit !!$invalid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | sub parse_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 6 | ▶ | eval {PICA::Path->new($_[0])} || die "invalid PICA Path: $_[0]\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_path: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | sub explain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | my ($self, $schema, $path) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
explain: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | if ($path->stringify =~ /[.]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | warn "Fields with wildcards cannot be explained yet!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $tag = $path->fields; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | my ($firstocc) = grep {$_ > 0} split '-', $path->occurrences; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $id = field_identifier($schema, [$tag, $firstocc]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $def = $schema->{fields}{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | if (defined $path->subfields && $def) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $path->subfields and $def
MC/DC0%0/2
defined $path->subfields and $def
defined $path->subfields
$def
Truth table0%0/3
A and B
A= defined $path->subfieldsB= $def
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | ▶ | my $sfdef = $def->{subfields} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$def->{'subfields'} || {}
MC/DC0%0/1
$def->{'subfields'} || {}
$def->{'subfields'}
Truth table0%0/2
A
A= $def->{'subfields'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | for (split '', $path->subfields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->document("$id\$$_", $sfdef->{$_}, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->document($id, $def, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | sub document { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | my ($self, $id, $def, $warn) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | my $writer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | = pica_writer('plain', color => ($self->{color} ? \%COLORS : undef)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($def) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $status = ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | ▶ | if ($def->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | $status = $def->{repeatable} ? '+' : '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | ▶ | $status = $def->{repeatable} ? '*' : 'o'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my ($field, $subfield) = split '\$', $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $writer->write_identifier([split '/', $field]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if (defined $subfield) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $writer->write_subfield($subfield, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | print "\t"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | print $self->{color} ? colored($status, $COLORS{value}) : $status; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | my $doc = "\t" . $def->{label} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
"\t" . $def->{"label"} // ""
MC/DC0%0/1
"\t" . $def->{"label"} // ""
"\t" . $def->{"label"}
Truth table0%0/2
A
A= "\t" . $def->{"label"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | utf8::decode($doc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | say $doc =~ s/[\s\r\n]+/ /mgr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | elsif (!$self->{unknown}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | ▶ | if ($warn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | warn "$id\t?\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | say $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | App::picadata - Implementation of picadata command line application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | This package implements the L<picadata> command line application. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | Copyright 2020- Jakob Voss | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||