| 1 | package PICA::Writer; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | $PICA::Writer::VERSION = '0.585'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | #ABSTRACT: Write and count PICA+ records and fields | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use PICA::Record; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use PICA::Parser; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use IO::Scalar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use String::Escape qw(qqbackslash elide); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use constant ERROR => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use constant NEW => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use constant STARTED => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use constant ENDED => 3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | 'bool' => sub { $_[0]->status }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 14 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 14 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 14 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 30 | status => NEW, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | io => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | options => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | recordcounter => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | fieldcounter => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 14 | ▶ | return $self->reset( @_ ? @_ : undef ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 14 | ▶ | sub output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output: called CC=18 SCAR=29.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 14 | ▶ | my ($output, %options) = @_ % 2 ? @_ : (undef, @_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 14 | %{ $self->{options} } = %options; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | my $format = $self->{options}->{format}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 14 | ▶ | if (not defined $output) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | $self->{io} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } elsif ( ref($output) eq 'GLOB' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | $self->{io} = $output; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | PICA::Parser::enable_binmode_encoding( $self->{io} ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ( UNIVERSAL::isa('IO::Handle', $output) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $self->{io} = $output; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | PICA::Parser::enable_binmode_encoding( $self->{io} ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } elsif ( ref($output) eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | $self->{io} = IO::Scalar->new( $output ); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | $self->{io} = IO::File->new($output, '>:utf8'); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | $format = 'xml' if not defined $format and $output =~ /\.xml$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $format and $output =~ /\.xml$/
MC/DC50%1/2
not defined $format and $output =~ /\.xml$/
not defined $format
$output =~ /\.xml$/
Truth table66%2/3
not(A) and B
A= not defined $formatB= $output =~ /\.xml$/
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 14 | ▶ | if ($options{pretty}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $options{DATA_MODE} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | $options{DATA_INDENT} = 2; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | $options{NAMESPACES} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $options{PREFIX_MAP} = {'info:srw/schema/5/picaXML-v1.0'=>''}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | ▶ | $format = 'plain' unless defined $format and $format =~ /^(plain|normalized|xml)$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $format and $format =~ /^(plain|normalized|xml)$/i
MC/DC50%1/2
defined $format and $format =~ /^(plain|normalized|xml)$/i
defined $format
$format =~ /^(plain|normalized|xml)$/i
Truth table66%2/3
A and B
A= defined $formatB= $format =~ /^(plain|normalized|xml)$/i
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | $self->{options}->{format} = lc($format); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 14 | ▶ | if ( $format =~ /^xml$/i and defined $output ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$format =~ /^xml$/i and defined $output
MC/DC50%1/2
$format =~ /^xml$/i and defined $output
$format =~ /^xml$/i
defined $output
Truth table66%2/3
A and B
A= $format =~ /^xml$/iB= defined $output
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $options{OUTPUT} = $self->{io}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | $options{header} = 1 unless defined $options{header}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | $self->{xmlwriter} = PICA::Writer::xmlwriter( %options ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | $self->{xmlwriter} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 14 | ▶ | if (defined $output and not $self->{io}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $output and not $self->{"io"}
MC/DC100%2/2
defined $output and not $self->{"io"}
defined $output
not $self->{"io"}
Truth table100%3/3
A and not(B)
A= defined $outputB= not $self->{"io"}
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | $self->{status} = ERROR; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 14 | ▶ | if ( $self->{options}->{stats} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $self->{fieldstat} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | $self->{subfieldstat} = {} if $self->{options}->{stats} > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 12 | $self->{subfieldstat} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | $self->{fieldstat} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 15 | ▶ | sub reset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 15 | ▶ | $self->output( @_ ) if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 15 | $self->{recordcounter} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 15 | $self->{fieldcounter} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=29 SCAR=55.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | ▶ | croak('cannot write to a closed writer') if $self->status == ENDED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 20 | ▶ | $self->start if $self->status != STARTED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 19 | my $format = $self->{options}->{format}; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 19 | ▶ | if (UNIVERSAL::isa($_[0],'PICA::Field')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (UNIVERSAL::isa($field,'PICA::Field')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ($format eq 'plain') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | print { $self->{io} } $field->string if $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | } elsif ($format eq 'normalized') { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | print { $self->{io} } $field->normalized() if $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | ▶ | } elsif ($format eq 'xml' and defined $self->{xmlwriter} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$format eq "xml" and defined $self->{"xmlwriter"}
MC/DC0%0/2
$format eq "xml" and defined $self->{"xmlwriter"}
$format eq "xml"
defined $self->{"xmlwriter"}
Truth table0%0/3
A and B
A= $format eq "xml"B= defined $self->{"xmlwriter"}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $field->xml( $self->{xmlwriter} ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->addfieldstat( $field ); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | croak("Cannot write object of unknown type (PICA::Field expected)!"); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 19 | my $comment = ""; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 19 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 20 | my $record = shift; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 20 | ▶ | if ( UNIVERSAL::isa($record, 'PICA::Record') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 20 | ▶ | if ($format eq 'plain') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | print { $self->{io} } "\n" | |||||||||||||||||||||||||||||||||||||||||
| 137 | 18 | ▶ | if ($self->{recordcounter} > 0 && $self->{io}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"recordcounter"} > 0 and $self->{"io"}
MC/DC100%2/2
$self->{"recordcounter"} > 0 and $self->{"io"}
$self->{"recordcounter"} > 0
$self->{"io"}
Truth table100%3/3
A and B
A= $self->{"recordcounter"} > 0B= $self->{"io"}
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 18 | ▶ | print { $self->{io} } $record->string if $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | } elsif ($format eq 'normalized') { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | print { $self->{io} } "\x1D\x0A" # next record | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($self->{recordcounter} > 0 && $self->{io}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"recordcounter"} > 0 and $self->{"io"}
MC/DC0%0/2
$self->{"recordcounter"} > 0 and $self->{"io"}
$self->{"recordcounter"} > 0
$self->{"io"}
Truth table0%0/3
A and B
A= $self->{"recordcounter"} > 0B= $self->{"io"}
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | print { $self->{io} } $record->normalized() if $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | ▶ | } elsif ($format eq 'xml' and defined $self->{xmlwriter} ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$format eq "xml" and defined $self->{"xmlwriter"}
MC/DC0%0/2
$format eq "xml" and defined $self->{"xmlwriter"}
$format eq "xml"
defined $self->{"xmlwriter"}
Truth table33%1/3
A and B
A= $format eq "xml"B= defined $self->{"xmlwriter"}
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $record->xml( $self->{xmlwriter} ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | $self->addrecordstat( $record ); | |||||||||||||||||||||||||||||||||||||||||
| 147 | } elsif (ref(\$record) eq 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | next if !$record; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $comment = '# ' . join("\n# ", split(/\n/,$record)) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $comment =~ s/--//g; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($format eq 'xml') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | $self->{xmlwriter}->comment( $comment ) | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if defined $self->{xmlwriter}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | print { $self->{io} } $comment if $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | croak("Cannot write object of unknown type (PICA::Record expected)!"); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 19 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 13 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 13 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 13 | ▶ | croak('cannot start a writer twice') if $self->status == STARTED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 13 | ▶ | croak('cannot start a writer in error status') if $self->status == ERROR; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 12 | my $writer = $self->{xmlwriter}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 12 | ▶ | if ( $self->{options}->{format} eq 'xml' and defined $writer ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"options"}{"format"} eq "xml" and defined $writer
MC/DC50%1/2
$self->{"options"}{"format"} eq "xml" and defined $writer
$self->{"options"}{"format"} eq "xml"
defined $writer
Truth table66%2/3
A and B
A= $self->{"options"}{"format"} eq "xml"B= defined $writer
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | ▶ | if (UNIVERSAL::isa( $writer, 'XML::Writer::Namespaces' )) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | $writer->startTag( [$PICA::Record::XMLNAMESPACE, 'collection'] ); | |||||||||||||||||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $writer->startTag( 'collection' ); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | $self->{status} = STARTED; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 12 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 7 | ▶ | croak('cannot end a writer in error status') if $self->status == ERROR; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 7 | ▶ | croak('cannot end a writer twice') if $self->status == ENDED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | $self->start if $self->status != STARTED; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | ▶ | if ( $self->{options}->{format} eq 'xml') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 2 | ▶ | if ( defined $self->{xmlwriter} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | $self->{xmlwriter}->endTag(); # </collection> | |||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | $self->{xmlwriter}->end(); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # other supported formats don't need end handling | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | ▶ | $self->{io}->close if defined $self->{io}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 7 | $self->{status} = ENDED; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 102 | ▶ | sub status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 102 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 102 | return $self->{status}; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 6 | ▶ | sub records { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
records: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 218 | 6 | return $self->{recordcounter}; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 13 | *counter = *records; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | ▶ | sub fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | return $self->{fieldcounter}; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 2 | ▶ | sub statlines { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
statlines: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | my @STRINGS = ('?',' ','*','+'); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | my @stats = (); | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | ▶ | my $fieldstat = $self->{fieldstat} || { }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'fieldstat'} || {}
MC/DC0%0/1
$self->{'fieldstat'} || {}
$self->{'fieldstat'}
Truth table50%1/2
A
A= $self->{'fieldstat'}
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | my $subfieldstat = $self->{subfieldstat}; | |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | foreach my $tag (sort { $a cmp $b } keys %{$fieldstat}) { | |||||||||||||||||||||||||||||||||||||||||
| 241 | 78 | ▶ | my $line = length($tag) < 5 ? "$tag " : "$tag "; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 78 | $line .= $STRINGS[ $fieldstat->{$tag} ]; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 78 | ▶ | if ( defined $subfieldstat ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 39 | my $s = $subfieldstat->{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 39 | foreach (keys %{$s}) { | |||||||||||||||||||||||||||||||||||||||||
| 246 | 60 | $line .= "\$$_ "; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 60 | $line .= $STRINGS[ $s->{$_}->{occ} ]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | $line .= qqbackslash(elide($s->{$_}->{val},40)) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 60 | ▶ | if defined $s->{$_}->{val}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 60 | $line .= " "; # TODO: join! | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 78 | push @stats, $line; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | return @stats; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 8 | ▶ | sub xmlwriter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xmlwriter: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 8 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | ▶ | $params{NAMESPACES} = 1 unless defined $params{NAMESPACES}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 8 | ▶ | if (not defined $params{PREFIX_MAP} or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params{"PREFIX_MAP"} and defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}
MC/DC50%1/2
defined $params{"PREFIX_MAP"} and defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}
defined $params{"PREFIX_MAP"}
defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}
Truth table66%2/3
A and B
A= defined $params{"PREFIX_MAP"}B= defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | not defined $params{PREFIX_MAP}->{ $PICA::Record::XMLNAMESPACE }) { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | $params{PREFIX_MAP} = { $PICA::Record::XMLNAMESPACE => 'pica' }; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 8 | my $writer = XML::Writer->new( %params ); | |||||||||||||||||||||||||||||||||||||||||
| 270 | 8 | ▶ | $writer->xmlDecl('UTF-8') if $params{header}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 8 | ▶ | if ($params{xslt}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | $writer->pi('xml-stylesheet', 'type="text/xsl" href="' . $params{xslt} . '"'); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 8 | return $writer; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 184 | ▶ | sub addfieldstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addfieldstat: called CC=16 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 184 | my ($self, $field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 184 | $self->{fieldcounter}++; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 184 | ▶ | return unless defined $self->{subfieldstat}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 92 | my $tag = $field->tag; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 92 | my (%o,%v); | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 92 | my @content = $field->content; | |||||||||||||||||||||||||||||||||||||||||
| 289 | #print Dumper($field->content); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 92 | foreach (@content) { | |||||||||||||||||||||||||||||||||||||||||
| 291 | 132 | my ($sf,$value) = @{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 132 | $o{ $sf }++; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 132 | ▶ | if ( exists $v{ $sf } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | ▶ | $v{ $sf } = undef unless defined $v{ $sf } and $v{ $sf } eq $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $v{$sf} and $v{$sf} eq $value
MC/DC0%0/2
defined $v{$sf} and $v{$sf} eq $value
defined $v{$sf}
$v{$sf} eq $value
Truth table33%1/3
A and B
A= defined $v{$sf}B= $v{$sf} eq $value
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 131 | $v{ $sf } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 92 | my $sfstat = $self->{subfieldstat}; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | # TODO: order of subfields | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 92 | my $all = $sfstat->{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 92 | ▶ | if ( $sfstat->{$tag} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 53 | foreach my $sf (keys %{$sfstat->{$tag}}) { | |||||||||||||||||||||||||||||||||||||||||
| 307 | 79 | my $cur = $sfstat->{$tag}->{$sf}; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 79 | ▶ | if ( $o{$sf} ) { # this time also | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | # .. | ||||||||||||||||||||||||||||||||||||||||||
| 310 | $cur->{occ} += 2 | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 71 | ▶ | if $o{$sf} > 1 and $cur->{occ} < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$o{$sf} > 1 and $cur->{"occ"} < 2
MC/DC0%0/2
$o{$sf} > 1 and $cur->{"occ"} < 2
$o{$sf} > 1
$cur->{"occ"} < 2
Truth table33%1/3
A and B
A= $o{$sf} > 1B= $cur->{"occ"} < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | $cur->{val} = undef unless | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 71 | ▶ | defined $v{$sf} and defined $cur->{val} and $v{$sf} eq $cur->{val}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $v{$sf} and defined $cur->{"val"} and $v{$sf} eq $cur->{"val"}
defined $v{$sf} and defined $cur->{"val"}
MC/DC66%2/3
defined $v{$sf} and defined $cur->{"val"} and $v{$sf} eq $cur->{"val"}
defined $v{$sf}
defined $cur->{"val"}
$v{$sf} eq $cur->{"val"}
Truth table75%3/4
A and B and C
A= defined $v{$sf}B= defined $cur->{"val"}C= $v{$sf} eq $cur->{"val"}
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 71 | delete $v{$sf}; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 71 | delete $o{$sf}; | |||||||||||||||||||||||||||||||||||||||||
| 317 | } else { # not this time but before | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 8 | ▶ | $cur->{occ} = $cur->{occ} > 1 ? 0 : 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # fehlende subfields hinzufügen | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 53 | foreach (keys %o) { | |||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | $sfstat->{$tag}->{$_} = { val => $v{$_}, occ => $o{$_} }; | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | $sfstat->{$tag} = { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 39 | map { $_ => { val => $v{$_}, occ => $o{$_} } } keys %o | |||||||||||||||||||||||||||||||||||||||||
| 329 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # ...stats... | ||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 20 | ▶ | sub addrecordstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addrecordstat: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 20 | my ($self, $record) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 20 | $self->{recordcounter}++; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 20 | ▶ | if ( not defined $self->{fieldstat} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 14 | $self->{fieldcounter} += scalar $record->fields; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | my $fieldstat = $self->{fieldstat}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | # add field stats | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 6 | my %count; # undef, one, repeatable | |||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | foreach my $field ($record->fields) { | |||||||||||||||||||||||||||||||||||||||||
| 349 | 184 | $self->addfieldstat( $field ); | |||||||||||||||||||||||||||||||||||||||||
| 350 | 184 | $count{ $field->tag }++; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | # 1, 3 : unique | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # 0,1,2,3 ?: optional, 1: mandatory, +: repeatable | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 6 | foreach my $tag (keys %{$fieldstat}) { | |||||||||||||||||||||||||||||||||||||||||
| 357 | 136 | ▶ | if ( $count{$tag} ) { # does exist this time but before only once | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 94 | ▶ | if ( $count{$tag} > 1 and $fieldstat->{$tag} < 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$count{$tag} > 1 and $fieldstat->{$tag} < 2
MC/DC0%0/2
$count{$tag} > 1 and $fieldstat->{$tag} < 2
$count{$tag} > 1
$fieldstat->{$tag} < 2
Truth table66%2/3
A and B
A= $count{$tag} > 1B= $fieldstat->{$tag} < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $fieldstat->{$tag} += 2; | |||||||||||||||||||||||||||||||||||||||||
| 360 | } #if $fieldstat->{$tag} < 2; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 94 | delete $count{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } else { # has existed before but not this time | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 42 | ▶ | $fieldstat->{$tag} = $fieldstat->{$tag} > 1 ? 0 : 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # new fields are '1' or '+' | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 6 | foreach my $tag (keys %count) { | |||||||||||||||||||||||||||||||||||||||||
| 369 | 78 | ▶ | $fieldstat->{$tag} = $count{$tag} > 1 ? 3 : 1; # | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | __END__ | ||||||||||||||||||||||||||||||||||||||||||