| 1 | package PICA::Data; | ||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 8 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 8 | our @EXPORT_OK = qw(pica_parser pica_writer pica_path pica_xml_struct | |||||||||||||||||||||||||||||||
| 8 | pica_match pica_values pica_value pica_fields pica_holdings pica_items | ||||||||||||||||||||||||||||||||
| 9 | pica_guess clean_pica pica_string); | ||||||||||||||||||||||||||||||||
| 10 | 8 | our %EXPORT_TAGS = (all => [@EXPORT_OK]); | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 8 | our $ILN_PATH = PICA::Path->new('101@a'); | |||||||||||||||||||||||||||||||
| 13 | 8 | our $EPN_PATH = PICA::Path->new('203@/..0'); | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 8 | ▶ | use Scalar::Util qw(reftype blessed); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | use List::Util qw(first any); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 8 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | use PICA::Path; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | sub pica_match { | ||||||||||||||||||||||||||||||||
| 23 | 58 | ▶ | my ($record, $path, %args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_match: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 58 | ▶ | $path = eval {PICA::Path->new($path)} unless ref $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 58 | ▶ | return unless ref $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 54 | return $path->match_record($record, %args); | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | sub pica_values { | ||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | my ($record, $path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_values: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 10 | ▶ | $path = eval {PICA::Path->new($path)} unless ref $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | 10 | ▶ | return unless ref $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 9 | return $path->record_subfields($record); | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | sub pica_fields { | ||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | my $record = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_fields: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | my @pathes = map { | ||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | ref $_ ? $_ : eval {PICA::Path->new($_)} | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | } @_; | ||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | return [ | ||||||||||||||||||||||||||||||||
| 49 | grep { | ||||||||||||||||||||||||||||||||
| 50 | 4 | my $cur = $_; | |||||||||||||||||||||||||||||||
| 51 | 71 | ▶ | any {$_->match_field($cur)} @pathes | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 52 | 72 | } @$record | |||||||||||||||||||||||||||||||
| 53 | ]; | ||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | sub pica_value { | ||||||||||||||||||||||||||||||||
| 57 | 8 | ▶ | my ($record, $path) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_value: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 8 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 8 | ▶ | $path = eval {PICA::Path->new($path)} unless ref $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 8 | ▶ | return unless defined $path; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 8 | foreach my $field (@$record) { | |||||||||||||||||||||||||||||||
| 64 | 70 | ▶ | next unless $path->match_field($field); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 65 | 9 | my @values = $path->match_subfields($field); | |||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | return $values[0] if @values; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 1 | return; | |||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | sub pica_items { | ||||||||||||||||||||||||||||||||
| 73 | 6 | ▶ | my ($record) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_items: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 6 | my $blessed = blessed($record); | |||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | 6 | my (@items, $current, $occurrence); | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 6 | foreach my $field (@$record) { | |||||||||||||||||||||||||||||||
| 80 | 6110 | ▶ | if ($field->[0] =~ /^2/) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 5726 | ▶ | if (($occurrence // '') ne $field->[1]) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$occurrence // ""
MC/DC100%1/1
$occurrence // ""
$occurrence
Truth table100%2/2
A
A= $occurrence
| |||||||||||||||||||||||||||||||||
| 83 | 710 | ▶ | if ($current) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 595 | push @items, $current; | |||||||||||||||||||||||||||||||
| 85 | 595 | $current = undef; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | 710 | $occurrence = $field->[1]; | |||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 5726 | ▶ | $current //= {record => []}; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$current //= {"record", []}
MC/DC100%1/1
$current //= {"record", []}
$current
Truth table100%2/2
A
A= $current
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 5726 | push @{$current->{record}}, [@$field]; | |||||||||||||||||||||||||||||||
| 93 | 5726 | ▶ | if ($field->[0] eq '203@') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 710 | ($current->{_id}) = $EPN_PATH->match_subfields($field); | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | elsif ($current) { | ||||||||||||||||||||||||||||||||
| 98 | 110 | push @items, $current; | |||||||||||||||||||||||||||||||
| 99 | 110 | $current = undef; | |||||||||||||||||||||||||||||||
| 100 | 110 | $occurrence = undef; | |||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | push @items, $current if $current; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | if ($blessed) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 107 | 4 | bless $_, $blessed for @items; | |||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 6 | return \@items; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | sub pica_holdings { | ||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | my ($record) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_holdings: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 3 | my $blessed = blessed($record); | |||||||||||||||||||||||||||||||
| 117 | 3 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | 3 | my (@holdings, $iln); | |||||||||||||||||||||||||||||||
| 119 | 3 | my $field_buffer = []; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 3 | foreach my $field (@$record) { | |||||||||||||||||||||||||||||||
| 122 | 3047 | my $tag = substr $field->[0], 0, 1; | |||||||||||||||||||||||||||||||
| 123 | 3047 | ▶ | if ($tag eq '0') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 124 | 42 | next; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | elsif ($tag eq '1') { | ||||||||||||||||||||||||||||||||
| 127 | 150 | ▶ | if ($field->[0] eq '101@') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | 57 | my ($id) = $ILN_PATH->match_subfields($field); | |||||||||||||||||||||||||||||||
| 129 | 57 | ▶ | if (defined $iln && ($id // '') ne $iln) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $iln and ($id // "") ne $iln
$id // ""
MC/DC50%1/2
defined $iln and ($id // "") ne $iln
defined $iln
$id
Truth table66%2/3
A and B
A= defined $ilnB= $id
| |||||||||||||||||||||||||||||||||
| 130 | 55 | push @holdings, {record => $field_buffer, _id => $iln}; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | 57 | $field_buffer = [[@$field]]; | |||||||||||||||||||||||||||||||
| 133 | 57 | $iln = $id; | |||||||||||||||||||||||||||||||
| 134 | 57 | next; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | 2948 | push @$field_buffer, [@$field]; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | if (@$field_buffer) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | 2 | push @holdings, {record => $field_buffer, _id => $iln}; | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | if ($blessed) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 2 | bless $_, $blessed for @holdings; | |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||
| 148 | 3 | return \@holdings; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | sub pica_string { | ||||||||||||||||||||||||||||||||
| 152 | 9 | ▶ | my ($pica, $type, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 153 | 9 | my $string = ""; | |||||||||||||||||||||||||||||||
| 154 | 9 | ▶ | $type ||= 'plain'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$type ||= "plain"
MC/DC100%1/1
$type ||= "plain"
$type
Truth table100%2/2
A
A= $type
| |||||||||||||||||||||||||||||||||
| 155 | 9 | $options{fh} = \$string; | |||||||||||||||||||||||||||||||
| 156 | 9 | ▶ | $options{start} //= 0; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"start"} //= 0
MC/DC0%0/1
$options{"start"} //= 0
$options{"start"}
Truth table50%1/2
A
A= $options{"start"}
| |||||||||||||||||||||||||||||||||
| 157 | 9 | pica_writer($type => %options)->write($pica); | |||||||||||||||||||||||||||||||
| 158 | 9 | return decode('UTF-8', $string); | |||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 8 | *fields = *pica_fields; | |||||||||||||||||||||||||||||||
| 162 | 8 | *holdings = *pica_holdings; | |||||||||||||||||||||||||||||||
| 163 | 8 | *items = *pica_items; | |||||||||||||||||||||||||||||||
| 164 | 8 | *match = *pica_match; | |||||||||||||||||||||||||||||||
| 165 | 8 | *value = *pica_value; | |||||||||||||||||||||||||||||||
| 166 | 8 | *values = *pica_values; | |||||||||||||||||||||||||||||||
| 167 | 8 | *string = *pica_string; | |||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | use PICA::Parser::XML; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 170 | 8 | ▶ | use PICA::Parser::Plus; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 171 | 8 | ▶ | use PICA::Parser::Plain; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 172 | 8 | ▶ | use PICA::Parser::Binary; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 173 | 8 | ▶ | use PICA::Parser::PPXML; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | use PICA::Parser::JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | use PICA::Writer::XML; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 176 | 8 | ▶ | use PICA::Writer::Plus; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 177 | 8 | ▶ | use PICA::Writer::Plain; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 178 | 8 | ▶ | use PICA::Writer::Binary; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 179 | 8 | ▶ | use PICA::Writer::PPXML; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 180 | 8 | ▶ | use PICA::Writer::JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 181 | 8 | ▶ | use PICA::Writer::Fields; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | sub pica_parser { | ||||||||||||||||||||||||||||||||
| 184 | 54 | ▶ | _pica_module('PICA::Parser', @_); | ||||||||||||||||||||||||||||||
|
Subroutine
pica_parser: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | sub pica_writer { | ||||||||||||||||||||||||||||||||
| 188 | 9 | ▶ | if (lc $_[0] eq 'generic') { | ||||||||||||||||||||||||||||||
|
Subroutine
pica_writer: called CC=2 SCAR=9.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 189 | 0 | shift; | |||||||||||||||||||||||||||||||
| 190 | 0 | return PICA::Writer::Generic->new(@_); | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | 9 | _pica_module('PICA::Writer', @_); | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | sub pica_path { | ||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | PICA::Path->new(@_); | ||||||||||||||||||||||||||||||
|
Subroutine
pica_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | sub pica_guess { | ||||||||||||||||||||||||||||||||
| 200 | 7 | ▶ | my ($pica) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_guess: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||
| 202 | 7 | my $format = ''; | |||||||||||||||||||||||||||||||
| 203 | 7 | my %count = ( | |||||||||||||||||||||||||||||||
| 204 | '' => 0, | ||||||||||||||||||||||||||||||||
| 205 | 'Plain' => ($pica =~ tr/$//), | ||||||||||||||||||||||||||||||||
| 206 | 'Plus' => ($pica =~ tr/\x{0A}//), | ||||||||||||||||||||||||||||||||
| 207 | 'Binary' => ($pica =~ tr/\x{1D}//), | ||||||||||||||||||||||||||||||||
| 208 | 'XML' => ($pica =~ tr/<//), | ||||||||||||||||||||||||||||||||
| 209 | 'JSON' => ($pica =~ tr/[{[]//), | ||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||
| 211 | 7 | ▶ | $count{$_} > $count{$format} and $format = $_ for grep {$_} keys %count; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 7 | ▶ | $format = 'PPXML' if $format eq 'XML' and $pica =~ qr{xmlns/ppxml-1\.0}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$format eq "XML" and $pica =~ qr"xmlns/ppxml-1\.0"u
MC/DC0%0/2
$format eq "XML" and $pica =~ qr"xmlns/ppxml-1\.0"u
$format eq "XML"
$pica =~ qr"xmlns/ppxml-1\.0"u
Truth table66%2/3
A and B
A= $format eq "XML"B= $pica =~ qr"xmlns/ppxml-1\.0"u
| |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | 7 | ▶ | $format ? "PICA::Parser::$format" : undef; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | sub _pica_module { | ||||||||||||||||||||||||||||||||
| 219 | 63 | ▶ | my $base = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_pica_module: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 220 | 63 | ▶ | my $type = lc(shift) // ''; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
lc shift() // ""
MC/DC0%0/1
lc shift() // ""
lc shift()
Truth table50%1/2
A
A= lc shift()
| |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 63 | ▶ | if ($type =~ /^(pica)?plus$/) { | ||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||
| 223 | 4 | "${base}::Plus"->new(@_); | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | elsif ($type eq 'binary') { | ||||||||||||||||||||||||||||||||
| 226 | 3 | "${base}::Binary"->new(@_); | |||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | elsif ($type =~ /^(pica)?plain$/) { | ||||||||||||||||||||||||||||||||
| 229 | 37 | "${base}::Plain"->new(@_); | |||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | elsif ($type =~ /^(pica)?xml$/) { | ||||||||||||||||||||||||||||||||
| 232 | 9 | "${base}::XML"->new(@_); | |||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | elsif ($type =~ /^(pica)?ppxml$/) { | ||||||||||||||||||||||||||||||||
| 235 | 3 | "${base}::PPXML"->new(@_); | |||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||
| 237 | elsif ($type =~ /^(nd)?json$/) { | ||||||||||||||||||||||||||||||||
| 238 | 6 | "${base}::JSON"->new(@_); | |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||
| 241 | 1 | croak "unknown PICA parser type: $type"; | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||
| 245 | sub write { | ||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $pica = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
write: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 247 | 0 | my $writer = $_[0]; | |||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | unless (blessed $writer) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | $writer = pica_writer(@_ ? @_ : 'plain'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||
| 251 | 0 | $writer->write($pica); | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | sub TO_JSON { | ||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | my $record = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | $record = $record->{record} if reftype $record eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | 1 | return [@$record]; | |||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | sub pica_xml_struct { | ||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | my ($xml, %options) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
pica_xml_struct: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 262 | 0 | my $record; | |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 0 | foreach my $f (@{$xml->[2]}) { | |||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | next unless $f->[0] eq 'datafield'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 266 | push @$record, | ||||||||||||||||||||||||||||||||
| 267 | [ | ||||||||||||||||||||||||||||||||
| 268 | 0 | map ({$f->[1]->{$_}} qw(tag occurrence)), | |||||||||||||||||||||||||||||||
| 269 | 0 | map ({$_->[1]->{code} => $_->[2]->[0]} @{$f->[2]}) | |||||||||||||||||||||||||||||||
| 270 | ]; | ||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 0 | my ($id) = map {$_->[-1]} grep {$_->[0] =~ '003@'} @$record; | |||||||||||||||||||||||||||||||
| 274 | 0 | $record = {_id => $id, record => $record}; | |||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | bless $record, 'PICA::Data' if !!$options{bless}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 276 | 0 | return $record; | |||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 8 | 1; | |||||||||||||||||||||||||||||||
| 280 | __END__ | ||||||||||||||||||||||||||||||||