| 1 | package PICA::Record; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | $PICA::Record::VERSION = '0.585'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | #ABSTRACT: Perl module for handling PICA+ records | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | our @EXPORT = qw(readpicarecord writepicarecord); | |||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | our @EXPORT_OK = qw(picarecord pgrep pmap); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | our $XMLNAMESPACE = 'info:srw/schema/5/picaXML-v1.0'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | our @CARP_NOT = qw(PICA::Field PICA::Parser); | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use PICA::Field; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use PICA::Parser; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 13 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use PerlIO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | use Carp qw(croak confess); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 48 | ▶ | 'bool' => sub { ! $_[0]->empty }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 13 | ▶ | '""' => sub { $_[0]->string }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 13 | ▶ | use sort 'stable'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # private method to append a field | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 11453 | ▶ | my $append_field = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 11453 | my ($self, $field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | # confess('append_failed') unless ref($field) eq 'PICA::Field'; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 11453 | ▶ | if ( $field->tag eq '003@' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 71 | $self->{_ppn} = $field->sf('0'); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 71 | ▶ | if ( $self->field('003@') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | $self->update( '003@', $field ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # TODO: limit occ and iln, epn | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 11451 | ▶ | return 0 if $field->empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 11449 | push(@{ $self->{_fields} }, $field); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 11449 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # private method to compile and cache a regular expression | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my %field_regex; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 692 | ▶ | my $get_regex = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 692 | my $reg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 692 | ▶ | return $reg if ref($reg) eq 'Regexp'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 690 | my $regex = $field_regex{ $reg }; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 690 | ▶ | if (!defined $regex) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Compile & stash | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 29 | $regex = qr/^$reg$/; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 29 | $field_regex{ $reg } = $regex; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 690 | return $regex; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 638 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 638 | my $class = shift; # if $_[0] and UNIVERSAL::isa( $_[0], 'PICA::Record' | |||||||||||||||||||||||||||||||||||||||||
| 76 | # shift if defined $_[0] and $_[0] eq $class; # called as function | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 638 | ▶ | $class = $class || ref($class); # Handle cloning | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$class || ref $class
MC/DC0%0/2
$class || ref $class
$class
ref $class
Truth table33%1/3
A || B
A= $classB= ref $class
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 638 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 80 | _fields => [], | ||||||||||||||||||||||||||||||||||||||||||
| 81 | _ppn => undef | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 638 | ▶ | return $self unless @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 620 | my $first = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 620 | ▶ | if (defined $first) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 619 | ▶ | if ($#_ == 0 and ref(\$first) eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$#_ == 0 and ref \$first eq "SCALAR"
MC/DC100%2/2
$#_ == 0 and ref \$first eq "SCALAR"
$#_ == 0
ref \$first eq "SCALAR"
Truth table100%3/3
A and B
A= $#_ == 0B= ref \$first eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | my @lines = split("\n", $first); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | my @l2 = split("\x1E", $first); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | if (@l2 > @lines) { # normalized | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | @lines = @l2; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | foreach my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 68 | $line =~ s/^\x1D//; # start of record | |||||||||||||||||||||||||||||||||||||||||
| 99 | 68 | ▶ | next if $line =~ /^\s*$/; # skip empty lines | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 62 | my $field = PICA::Field->parse($line); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 61 | ▶ | $append_field->( $self, $field ) if $field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 606 | ▶ | } elsif (ref($first) eq 'GLOB' or eval { $first->isa('IO::Handle') }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $first eq "GLOB" or eval {
do {
$first->isa("IO::Handle")
}
}
MC/DC100%2/2
ref $first eq "GLOB" or eval {
do {
$first->isa("IO::Handle")
}
}
ref $first eq "GLOB"
eval {
do {
$first->isa("IO::Handle")
}
}
Truth table100%3/3
A or B
A= ref $first eq "GLOB"B= eval {
do {
$first->isa("IO::Handle")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 3110 | ▶ | PICA::Parser->parsefile( $first, Limit => 1, Field => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3110 | $append_field->( $self, shift ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 3110 | return; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | }); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 600 | $self->append( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | croak('Undefined parameter in PICA::Record->new'); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 618 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } # new() | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return PICA::Record->new( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 88 | ▶ | sub field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 88 | ▶ | my $limit = looks_like_number($_[0]) ? shift : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 88 | my @specs = @_; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 88 | ▶ | my $test = ref($specs[-1]) eq 'CODE' ? pop @specs : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 88 | ▶ | @specs = (".*") if $test and not @specs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$test and not @specs
MC/DC100%2/2
$test and not @specs
$test
not @specs
Truth table100%3/3
A and not(B)
A= $testB= not @specs
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 88 | ▶ | return unless @specs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 88 | my @list = (); | |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 88 | for my $tag ( @specs ) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 90 | my $regex = $get_regex->($tag); | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 90 | for my $maybe ( $self->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 141 | 431 | ▶ | if ( $maybe->tag() =~ $regex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 44 | local $_ = $maybe; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 44 | ▶ | if ( not $test or $test->($maybe) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $test or &$test($maybe)
MC/DC50%1/2
not $test or &$test($maybe)
not $test
&$test($maybe)
Truth table66%2/3
not(A) or B
A= not $testB= &$test($maybe)
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 39 | ▶ | return $maybe unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 35 | push( @list, $maybe ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 35 | ▶ | if ($limit > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | return @list unless --$limit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 82 | return @list; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } # field() | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | # Shortcut | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | *f = \&field; | |||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 581 | ▶ | sub subfield { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subfield: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 581 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 581 | ▶ | my $limit = looks_like_number($_[0]) ? shift : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 581 | ▶ | return unless defined $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 581 | my @list = (); | |||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 581 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 588 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 588 | my $subfield; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 588 | ▶ | croak "Not a field or full pattern: $tag" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | unless $tag =~ /^([^\$_]{3,})([\$_]([^\$_]+))?/; | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 588 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 574 | ($tag, $subfield) = ($1, $3); | |||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 14 | $subfield = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 588 | ▶ | croak("Missing subfield for $tag") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | unless defined $subfield; | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 588 | my $tag_regex = $get_regex->($tag); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 588 | for my $f ( $self->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 185 | 824 | ▶ | if ( $f->tag() =~ $tag_regex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 596 | my @s = $f->subfield($subfield); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 596 | ▶ | if (@s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 594 | ▶ | return shift @s unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 35 | ▶ | if ($limit > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 10 | ▶ | if (scalar @s >= $limit) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | push @list, @s[0..($limit-1)]; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | return @list; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | $limit -= scalar @s; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 30 | push( @list, @s ); | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 17 | ▶ | return $list[0] unless wantarray; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 15 | return @list; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } # subfield() | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # Shortcut | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 13 | *sf = \&subfield; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 8 | ▶ | sub values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | my @values = $self->subfield( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | return @values; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 741 | ▶ | sub fields() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 741 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 741 | ▶ | croak("You called all_fields() but you probably want field()") if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 741 | return @{$self->{_fields}}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | ▶ | sub size { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | return 1 * @{$self->{_fields}}; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | sub occurrence { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occurrence: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | ▶ | return unless $self->{_fields}->[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | return $self->{_fields}->[0]->occurrence; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | ▶ | sub occ { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
occ: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | return shift->occurrence; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my @fields = $self->field("0...(/..)?"); | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | return PICA::Record->new(@fields); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 7 | ▶ | sub holdings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
holdings: called CC=15 SCAR=28.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 7 | my ($self, $iln) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 7 | my %holdings = (); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | my @fields = (); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 7 | my $prevtag; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 7 | my $curiln = ''; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | my @pending; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 7 | foreach my $f (@{$self->{_fields}}) { | |||||||||||||||||||||||||||||||||||||||||
| 259 | 9187 | ▶ | next if $f->tag =~ /^0/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 9035 | ▶ | if ($f->tag eq '101@' and defined $f->sf('a')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$f->tag eq "101\@" and defined $f->sf("a")
MC/DC50%1/2
$f->tag eq "101\@" and defined $f->sf("a")
$f->tag eq "101\@"
defined $f->sf("a")
Truth table66%2/3
A and B
A= $f->tag eq "101\@"B= defined $f->sf("a")
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 175 | $curiln = $f->sf('a'); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 175 | ▶ | $holdings{$curiln} //= [ ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$holdings{$curiln} //= []
MC/DC0%0/1
$holdings{$curiln} //= []
$holdings{$curiln}
Truth table50%1/2
A
A= $holdings{$curiln}
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 175 | ▶ | if (@pending) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | push @{ $holdings{$curiln} }, @pending; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | @pending = (); | |||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 175 | push @{ $holdings{$curiln} }, $f; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } elsif( $curiln eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | push @pending, $f; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 8860 | push @{ $holdings{$curiln} }, $f; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 9035 | push @fields, $f; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 9035 | $prevtag = $f->tag; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | push @{ $holdings{$curiln} }, @pending if @pending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 7 | ▶ | if ($iln) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | %holdings = ($iln => $holdings{$iln}); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | %holdings = () unless $holdings{$iln}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 7 | foreach my $iln (keys %holdings) { | |||||||||||||||||||||||||||||||||||||||||
| 287 | 65 | @{$holdings{$iln}} = sort { | |||||||||||||||||||||||||||||||||||||||||
| 288 | 3578 | my ($ta,$tb) = ($a->tag, $b->tag); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 3578 | $ta =~ s{^(2...)/(..)$}{2$2$1}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 3578 | $tb =~ s{^(2...)/(..)$}{2$2$1}; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 3578 | $ta cmp $tb; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 65 | } @{$holdings{$iln}}; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 272 | ▶ | my @h = sort { ($a->iln // '0') <=> ($b->iln // '0') } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$a->iln // 0
$b->iln // 0
MC/DC0%0/1
$a->iln // 0
$a->iln
MC/DC0%0/1
$b->iln // 0
$b->iln
Truth table50%1/2
A
A= $a->iln
Truth table50%1/2
A
A= $b->iln
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 7 | map { PICA::Record->new( @$_ ) } CORE::values(%holdings); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 7 | ▶ | return $iln ? $h[0] : @h; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | sub items { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
items: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 5 | my @copies = (); | |||||||||||||||||||||||||||||||||||||||||
| 306 | 5 | my @fields = (); | |||||||||||||||||||||||||||||||||||||||||
| 307 | 5 | my $prevocc; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 5 | foreach my $f (@{$self->{_fields}}) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 3332 | ▶ | next unless $f->tag =~ /^[^0]/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 3269 | ▶ | if ($f->tag =~ /^1/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 181 | $prevocc = undef; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 181 | ▶ | push @copies, PICA::Record->new(@fields) if (@fields); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 181 | @fields = (); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 3088 | ▶ | next unless $f->tag =~ /^2...\/(..)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 3088 | ▶ | if (!($prevocc && $prevocc eq $1)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prevocc and $prevocc eq $1
MC/DC100%2/2
$prevocc and $prevocc eq $1
$prevocc
$prevocc eq $1
Truth table100%3/3
A and B
A= $prevoccB= $prevocc eq $1
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 385 | $prevocc = $1; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 385 | ▶ | push @copies, PICA::Record->new(@fields) if (@fields); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 385 | @fields = (); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 3088 | push @fields, $f; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 5 | ▶ | push @copies, PICA::Record->new(@fields) if (@fields); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | return @copies; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 149 | ▶ | sub empty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 149 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 149 | foreach my $field (@{$self->{_fields}}) { | |||||||||||||||||||||||||||||||||||||||||
| 336 | 128 | ▶ | return 0 if !$field->empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 21 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 5 | ▶ | sub ppn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ppn: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | ▶ | if ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | my $ppn = shift; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | ▶ | if (defined $ppn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | $append_field->( $self, PICA::Field->new('003@', '0' => $ppn) ) | |||||||||||||||||||||||||||||||||||||||||
| 348 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $self->remove('003@'); | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | return $self->{_ppn}; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 4 | ▶ | sub epn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
epn: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 358 | #for(my $i=0; $i<@_; $i++) { | ||||||||||||||||||||||||||||||||||||||||||
| 359 | # # TODO: add EPNs | ||||||||||||||||||||||||||||||||||||||||||
| 360 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 4 | return $self->subfield('203@/..$0'); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 545 | ▶ | sub iln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iln: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | # TODO: set ILN with this method and check uniqueness | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 545 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 545 | return $self->subfield('101@$a'); | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 608 | ▶ | sub append { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 608 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 374 | # TODO: this method can be simplified by use of ->new (see appendif) | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 608 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 608 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Append a field (whithout creating a copy) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 622 | ▶ | while (@_ and UNIVERSAL::isa($_[0],'PICA::Field') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and UNIVERSAL::isa($_[0], "PICA::Field")
MC/DC100%2/2
@_ and UNIVERSAL::isa($_[0], "PICA::Field")
@_
UNIVERSAL::isa($_[0], "PICA::Field")
Truth table100%3/3
A and B
A= @_B= UNIVERSAL::isa($_[0], "PICA::Field")
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 8221 | $c += $append_field->( $self, shift ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | # Append a whole record (copy all its fields) | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 622 | ▶ | while (@_ and UNIVERSAL::isa($_[0],'PICA::Record')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ and UNIVERSAL::isa($_[0], "PICA::Record")
MC/DC100%2/2
@_ and UNIVERSAL::isa($_[0], "PICA::Record")
@_
UNIVERSAL::isa($_[0], "PICA::Record")
Truth table100%3/3
A and B
A= @_B= UNIVERSAL::isa($_[0], "PICA::Record")
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | my $record = shift; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | for my $field ( $record->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 387 | 22 | $c += $append_field->( $self, $field->copy ); | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 622 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 36 | my @params = (shift); # tag | |||||||||||||||||||||||||||||||||||||||||
| 392 | 36 | ▶ | while (@_ and defined $_[0] and length($_[0]) == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
@_ and defined $_[0] and length $_[0] == 1
@_ and defined $_[0]
MC/DC66%2/3
@_ and defined $_[0] and length $_[0] == 1
@_
defined $_[0]
length $_[0] == 1
Truth table75%3/4
A and B and C
A= @_B= defined $_[0]C= length $_[0] == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | 41 | push @params, shift; # subfield | |||||||||||||||||||||||||||||||||||||||||
| 394 | 41 | push @params, shift; # value | |||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 36 | ▶ | $c += $append_field->( $self, PICA::Field->new( @params ) ) if @params > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | #use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
| 401 | #print Dumper(\@_)."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 402 | # local $Carp::CarpLevel = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 608 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | ▶ | sub appendif { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
appendif: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | my $append = PICA::Record->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | for my $field ( $append->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | $field = $field->purged(); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | ▶ | $append_field->( $self, $field ) if $field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 9 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 9 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 9 | ▶ | croak("Not a valid tag: $tag") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | unless PICA::Field::parse_pp_tag( $tag ); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 9 | my $replace; | |||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 9 | ▶ | return unless @_; # ignore | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 8 | ▶ | if ( not defined $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | $replace = shift; | |||||||||||||||||||||||||||||||||||||||||
| 433 | ▶ | } elsif ( UNIVERSAL::isa( $_[0], 'PICA::Field' ) or ref($_[0]) eq 'CODE' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
UNIVERSAL::isa($_[0], "PICA::Field") or ref $_[0] eq "CODE"
MC/DC100%2/2
UNIVERSAL::isa($_[0], "PICA::Field") or ref $_[0] eq "CODE"
UNIVERSAL::isa($_[0], "PICA::Field")
ref $_[0] eq "CODE"
Truth table100%3/3
A or B
A= UNIVERSAL::isa($_[0], "PICA::Field")B= ref $_[0] eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 4 | $replace = shift; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 3 | $replace = PICA::Field->new($tag, @_); | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | 8 | my $regex = $get_regex->($tag); | |||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | for my $field ( $self->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 442 | 36 | ▶ | if ( $field->tag() =~ $regex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 8 | my $rep = $replace; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 8 | ▶ | if ( UNIVERSAL::isa( $replace, 'CODE' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 2 | $rep = $rep->( $field ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | 2 | ▶ | $rep = undef unless UNIVERSAL::isa( $rep, 'PICA::Field' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 8 | ▶ | if (defined $rep) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 7 | ▶ | $self->{_ppn} = $rep->sf('0') if $rep->tag eq '003@'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 7 | $field->replace( $rep ); | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 8 | ▶ | return unless ref($replace) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 5 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 5 | my @specs = @_; | |||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 5 | ▶ | return 0 if !@specs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 5 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 5 | for my $tag ( @specs ) { | |||||||||||||||||||||||||||||||||||||||||
| 466 | 6 | my $regex = $get_regex->($tag); | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 6 | my $i=0; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 6 | for my $maybe ( $self->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 470 | 47 | ▶ | if ( $maybe->tag() =~ $regex ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 32 | ▶ | $self->{_ppn} = undef if $maybe->tag() eq '003@'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 32 | splice( @{$self->{_fields}}, $i, 1); | |||||||||||||||||||||||||||||||||||||||||
| 473 | 32 | $c++; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 15 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | } # for $tag | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 5 | return $c; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 2 | ▶ | sub sort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 485 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 2 | my $main = $self->main; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 2 | my @holdings = $self->holdings; | |||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | @{$self->{_fields}} = sort { $a->tag cmp $b->tag } @{$main->{_fields}}; | |||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 2 | foreach my $h ( @holdings ) { | |||||||||||||||||||||||||||||||||||||||||
| 493 | 4 | push @{$self->{_fields}}, @{$h->{_fields}}; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 2 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | sub add_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_headers: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | my $eln = $params{eln}; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | croak("add_headers needs an ELN") unless defined $eln; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | my $status = $params{status}; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | croak("add_headers needs status") unless defined $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | my @timestamp = defined $params{timestamp} ? @{$params{timestamp}} : localtime; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | # TODO: Test timestamp | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $hdate = strftime ("$eln:%d-%m-%g", @timestamp); | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $htime = strftime ("%H:%M:%S", @timestamp); | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | # Pica3: 000K - Unicode-Kennzeichen | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $self->append( "001U", '0' => 'utf8' ); | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | # PICA3: 0200 - Kennung und Datum der Ersterfassung | ||||||||||||||||||||||||||||||||||||||||||
| 519 | # http://www.gbv.de/vgm/info/mitglieder/02Verbund/01Erschliessung/02Richtlinien/01KatRicht/0200.pdf | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->append( "001A", '0' => $hdate ); | |||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | # PICA3: 0200 - Kennung und Datum der letzten Aenderung | ||||||||||||||||||||||||||||||||||||||||||
| 523 | # http://www.gbv.de/vgm/info/mitglieder/02Verbund/01Erschliessung/02Richtlinien/01KatRicht/0210.pdf | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $self->append( "001B", '0' => $hdate, 't' => $htime ); | |||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | # PICA3: 0230 - Kennung und Datum der Statusaenderung | ||||||||||||||||||||||||||||||||||||||||||
| 527 | # http://www.gbv.de/vgm/info/mitglieder/02Verbund/01Erschliessung/02Richtlinien/01KatRicht/0230.pdf | ||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | $self->append( "001D", '0' => $hdate ); | |||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | # PCIA3: 0500 - Bibliographische Gattung und Status | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # http://www.gbv.de/vgm/info/mitglieder/02Verbund/01Erschliessung/02Richtlinien/01KatRicht/0500.pdf | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $self->append( "002@", '0' => $status ); | |||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 59 | ▶ | sub string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 59 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 59 | ▶ | $args{endfield} = "\n" unless defined($args{endfield}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 59 | my @lines = (); | |||||||||||||||||||||||||||||||||||||||||
| 542 | 59 | for my $field ( @{$self->{_fields}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 543 | 796 | push( @lines, $field->string(%args) ); | |||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 59 | return join('', @lines); | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 6 | ▶ | sub normalized() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalized: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 6 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||
| 552 | 6 | ▶ | $prefix = "" if (!$prefix); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 6 | my @lines = (); | |||||||||||||||||||||||||||||||||||||||||
| 555 | 6 | for my $field ( @{$self->{_fields}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 556 | 6 | push( @lines, $field->normalized() ); | |||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 6 | return "\x1D\x0A" . $prefix . join( "", @lines ); | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 3 | ▶ | sub xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xml: called CC=6 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | my $writer = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 3 | my ($string, $sref); | |||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | # write to a string | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 3 | ▶ | if (not UNIVERSAL::isa( $writer, 'XML::Writer' )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if (not defined $params{OUTPUT}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $sref = \$string; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $params{OUTPUT} = $sref; | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $writer = PICA::Writer::xmlwriter( %params ); | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | 3 | ▶ | if ( UNIVERSAL::isa( $writer, 'XML::Writer::Namespaces' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 3 | $writer->startTag( [$PICA::Record::XMLNAMESPACE, 'record'] ); | |||||||||||||||||||||||||||||||||||||||||
| 580 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $writer->startTag( 'record' ); | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 3 | for my $field ( @{$self->{_fields}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 584 | 12 | $field->xml( $writer ); | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 3 | $writer->endTag(); | |||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 3 | ▶ | return defined $sref ? $$sref : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | ▶ | sub html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
html: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my @html = ("<div class='record'>\n"); | |||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | for my $field ( @{$self->{_fields}} ) { | |||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | push @html, $field->html( %options ); | |||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | push @html, "</div>"; | |||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | return join("", @html) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||
| 606 | 5 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | 5 | my $record = shift; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 5 | my $writer = PICA::Writer->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 609 | 5 | ▶ | return $writer unless $writer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 4 | $writer->write( $record )->end; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | ▶ | sub pgrep (&@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pgrep: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | my $block = shift; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | my $record = (@_ == 1 and UNIVERSAL::isa( $_[0],'PICA::Record' )) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and UNIVERSAL::isa($_[0], "PICA::Record")
MC/DC50%1/2
@_ == 1 and UNIVERSAL::isa($_[0], "PICA::Record")
@_ == 1
UNIVERSAL::isa($_[0], "PICA::Record")
Truth table66%2/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "PICA::Record")
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | ? $_[0] : PICA::Record->new( @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | my @fields; | |||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | for my $f ( $record->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 622 | 6 | local $_ = $f; | |||||||||||||||||||||||||||||||||||||||||
| 623 | 6 | ▶ | push @fields, $f if $block->(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | 2 | return PICA::Record->new( @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | ▶ | sub pmap (&@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pmap: called CC=6 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | my $block = shift; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | ▶ | my $record = (@_ == 1 and UNIVERSAL::isa( $_[0],'PICA::Record' )) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and UNIVERSAL::isa($_[0], "PICA::Record")
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "PICA::Record")
@_ == 1
UNIVERSAL::isa($_[0], "PICA::Record")
Truth table33%1/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "PICA::Record")
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | ? $_[0] : PICA::Record->new( @_ ); | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | my @fields; | |||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | 1 | for my $f ( $record->fields ) { | |||||||||||||||||||||||||||||||||||||||||
| 637 | 3 | local $_ = $f; | |||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | my @r = $block->(); | |||||||||||||||||||||||||||||||||||||||||
| 639 | 3 | ▶ | if (@r == 1 and UNIVERSAL::isa( $_[0],'PICA::Field' )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@r == 1 and UNIVERSAL::isa($_[0], "PICA::Field")
MC/DC0%0/2
@r == 1 and UNIVERSAL::isa($_[0], "PICA::Field")
@r == 1
UNIVERSAL::isa($_[0], "PICA::Field")
Truth table33%1/3
A and B
A= @r == 1B= UNIVERSAL::isa($_[0], "PICA::Field")
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | push @fields, $r[0]; | |||||||||||||||||||||||||||||||||||||||||
| 641 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | push @fields, PICA::Field->new( @r ); | |||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | return PICA::Record->new( @fields ); | |||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 10 | ▶ | sub readpicarecord { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readpicarecord: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 10 | my ($file, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 10 | ▶ | if ( wantarray and defined $options{Limit} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
wantarray and defined $options{"Limit"}
MC/DC100%2/2
wantarray and defined $options{"Limit"}
wantarray
defined $options{"Limit"}
Truth table100%3/3
A and B
A= wantarrayB= defined $options{"Limit"}
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | return PICA::Parser->parsefile( $file, %options )->records(); | |||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | 9 | $options{Limit} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 656 | 9 | my ($record) = PICA::Parser->parsefile( $file, %options )->records(); | |||||||||||||||||||||||||||||||||||||||||
| 657 | 9 | ▶ | return undef unless $record and not $record->empty; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$record and not $record->empty
MC/DC0%0/2
$record and not $record->empty
$record
not $record->empty
Truth table33%1/3
A and not(B)
A= $recordB= not $record->empty
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 9 | return $record; | |||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 13 | *writepicarecord = *write; | |||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | ▶ | sub picarecord { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
picarecord: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 1 | return PICA::Record->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | __END__ | ||||||||||||||||||||||||||||||||||||||||||