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