Writer.pm

filter: Statementstmt 88.4% 206 / 233 Branchbran 67.3% 93 / 138 Conditioncond 57.4% 27 / 47 MC/DCmcdc 36.6% 11 / 30 Subroutinesub 100% 28 / 28 Podpod 100% 13 / 13 totaltotal 77.3% 378 / 489 CC 94 SCAR 42.1
CC
94
Cov
78%
write
249.5
output
18.3
addfieldstat
16.5
CRAP 67.2
↑ Summary SOAPClient.pm »
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
BranchTrueFalseTotal
@_ ? : 12 2 14
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
BranchTrueFalseTotal
@_ % 2 ? : 12 2 14
43  
44 14 %{ $self->{options} } = %options;
45 14 my $format = $self->{options}->{format};
46  
47 14 ▶ if (not defined $output) {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $output) { } 4 10 14
elsif (ref $output eq 'GLOB') { } 2 8 10
elsif (UNIVERSAL::isa('IO::Handle', $output)) { } 0 8 8
elsif (ref $output eq 'SCALAR') { } 2 6 8
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
BranchTrueFalseTotal
if not defined $format and $output =~ /\.xml$/ 1 5 6
Condition66%2/3
not defined $format and $output =~ /\.xml$/
!ll&&!rl&&r
051
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$/
ABresult
0X0
100
111
60 }
61  
62 14 ▶ if ($options{pretty}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"pretty"}) 1 13 14
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
BranchTrueFalseTotal
unless defined $format and $format =~ /^(plain|normalized|xml)$/i 12 2 14
Condition66%2/3
defined $format and $format =~ /^(plain|normalized|xml)$/i
!ll&&!rl&&r
1202
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
ABresult
0X0
100
111
70  
71 14 $self->{options}->{format} = lc($format);
72 14 ▶ if ( $format =~ /^xml$/i and defined $output ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^xml$/i and defined $output) { } 2 12 14
Condition66%2/3
$format =~ /^xml$/i and defined $output
!ll&&!rl&&r
1202
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
ABresult
0X0
100
111
73 2 $options{OUTPUT} = $self->{io};
74 2 ▶ $options{header} = 1 unless defined $options{header};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"header"} 2 0 2
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
BranchTrueFalseTotal
if (defined $output and not $self->{"io"}) 2 12 14
Condition100%3/3
defined $output and not $self->{"io"}
!ll&&!rl&&r
482
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"}
ABresult
0X0
100
111
81 2 $self->{status} = ERROR;
82 }
83  
84 14 ▶ if ( $self->{options}->{stats} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'options'}{'stats'}) { } 2 12 14
85 2 $self->{fieldstat} = {};
86 2 ▶ $self->{subfieldstat} = {} if $self->{options}->{stats} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"stats"} > 1 1 1 2
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
BranchTrueFalseTotal
if @_ 14 1 15
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
BranchTrueFalseTotal
if $self->status == 3 0 20 20
110 20 ▶ $self->start if $self->status != STARTED;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status != 2 13 7 20
111  
112 19 my $format = $self->{options}->{format};
113  
114 19 ▶ if (UNIVERSAL::isa($_[0],'PICA::Field')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_[0], 'PICA::Field')) { } 0 19 19
115 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
116 0 my $field = shift;
117 0 ▶ if (UNIVERSAL::isa($field,'PICA::Field')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($field, 'PICA::Field')) { } 0 0 0
118 0 ▶ if ($format eq 'plain') {
Branch: 3 branches
BranchTrueFalseTotal
if ($format eq 'plain') { } 0 0 0
elsif ($format eq 'normalized') { } 0 0 0
elsif ($format eq 'xml' and defined $self->{'xmlwriter'}) { } 0 0 0
119 0 ▶ print { $self->{io} } $field->string if $self->{io};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"io"} 0 0 0
120 } elsif ($format eq 'normalized') {
121 0 ▶ print { $self->{io} } $field->normalized() if $self->{io};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"io"} 0 0 0
122 ▶ } elsif ($format eq 'xml' and defined $self->{xmlwriter} ) {
Condition0%0/3
$format eq "xml" and defined $self->{"xmlwriter"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (@_) 20 19 39
133 20 my $record = shift;
134 20 ▶ if ( UNIVERSAL::isa($record, 'PICA::Record') ) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($record, 'PICA::Record')) { } 20 0 20
elsif (ref \$record eq 'SCALAR') { } 0 0 0
135 20 ▶ if ($format eq 'plain') {
Branch: 3 branches
BranchTrueFalseTotal
if ($format eq 'plain') { } 18 2 20
elsif ($format eq 'normalized') { } 0 2 2
elsif ($format eq 'xml' and defined $self->{'xmlwriter'}) { } 2 0 2
136 1 print { $self->{io} } "\n"
137 18 ▶ if ($self->{recordcounter} > 0 && $self->{io});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"recordcounter"} > 0 and $self->{"io"} 1 17 18
Condition100%3/3
$self->{"recordcounter"} > 0 and $self->{"io"}
!ll&&!rl&&r
1161
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"}
ABresult
0X0
100
111
138 18 ▶ print { $self->{io} } $record->string if $self->{io};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"io"} 7 11 18
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
BranchTrueFalseTotal
if $self->{"recordcounter"} > 0 and $self->{"io"} 0 0 0
Condition0%0/3
$self->{"recordcounter"} > 0 and $self->{"io"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
142 0 ▶ print { $self->{io} } $record->normalized() if $self->{io};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"io"} 0 0 0
143 ▶ } elsif ($format eq 'xml' and defined $self->{xmlwriter} ) {
Condition33%1/3
$format eq "xml" and defined $self->{"xmlwriter"}
!ll&&!rl&&r
002
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $record 0 0 0
149 0 $comment = '# ' . join("\n# ", split(/\n/,$record)) . "\n";
150 0 $comment =~ s/--//g;
151 0 ▶ if ($format eq 'xml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'xml') { } 0 0 0
152 $self->{xmlwriter}->comment( $comment )
153 0 ▶ if defined $self->{xmlwriter};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"xmlwriter"} 0 0 0
154 } else {
155 0 ▶ print { $self->{io} } $comment if $self->{io};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"io"} 0 0 0
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
BranchTrueFalseTotal
if $self->status == 2 0 13 13
170 13 ▶ croak('cannot start a writer in error status') if $self->status == ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status == 0 1 12 13
171  
172 12 my $writer = $self->{xmlwriter};
173 12 ▶ if ( $self->{options}->{format} eq 'xml' and defined $writer ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"format"} eq "xml" and defined $writer) 2 10 12
Condition66%2/3
$self->{"options"}{"format"} eq "xml" and defined $writer
!ll&&!rl&&r
1002
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
ABresult
0X0
100
111
174 2 ▶ if (UNIVERSAL::isa( $writer, 'XML::Writer::Namespaces' )) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($writer, 'XML::Writer::Namespaces')) { } 2 0 2
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
BranchTrueFalseTotal
if $self->status == 0 0 7 7
191 7 ▶ croak('cannot end a writer twice') if $self->status == ENDED;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status == 3 0 7 7
192 7 ▶ $self->start if $self->status != STARTED;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status != 2 0 7 7
193  
194 7 ▶ if ( $self->{options}->{format} eq 'xml') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'options'}{'format'} eq 'xml') { } 2 5 7
195 2 ▶ if ( defined $self->{xmlwriter} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"xmlwriter"}) 2 0 2
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
BranchTrueFalseTotal
if defined $self->{"io"} 7 0 7
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'} || {}
l!l
20
MC/DC0%0/1
$self->{'fieldstat'} || {}
$self->{'fieldstat'}
Truth table50%1/2
A
A= $self->{'fieldstat'}
Aresult
11
00
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
BranchTrueFalseTotal
length $tag < 5 ? : 56 22 78
242 78 $line .= $STRINGS[ $fieldstat->{$tag} ];
243 78 ▶ if ( defined $subfieldstat ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subfieldstat) 39 39 78
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
BranchTrueFalseTotal
if defined $s->{$_}{"val"} 26 34 60
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
BranchTrueFalseTotal
unless defined $params{"NAMESPACES"} 4 4 8
265 8 ▶ if (not defined $params{PREFIX_MAP} or
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"PREFIX_MAP"} and defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}) 4 4 8
Condition66%2/3
defined $params{"PREFIX_MAP"} and defined $params{"PREFIX_MAP"}{$PICA::Record::XMLNAMESPACE}
!ll&&!rl&&r
404
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}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if $params{"header"} 3 5 8
271 8 ▶ if ($params{xslt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"xslt"}) 2 6 8
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
BranchTrueFalseTotal
unless defined $self->{"subfieldstat"} 92 92 184
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
BranchTrueFalseTotal
if (exists $v{$sf}) { } 1 131 132
295 1 ▶ $v{ $sf } = undef unless defined $v{ $sf } and $v{ $sf } eq $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v{$sf} and $v{$sf} eq $value 1 0 1
Condition33%1/3
defined $v{$sf} and $v{$sf} eq $value
!ll&&!rl&&r
010
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($sfstat->{$tag}) { } 53 39 92
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
BranchTrueFalseTotal
if ($o{$sf}) { } 71 8 79
309 # ..
310 $cur->{occ} += 2
311 71 ▶ if $o{$sf} > 1 and $cur->{occ} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $o{$sf} > 1 and $cur->{"occ"} < 2 0 71 71
Condition33%1/3
$o{$sf} > 1 and $cur->{"occ"} < 2
!ll&&!rl&&r
7100
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
ABresult
0X0
100
111
312  
313 $cur->{val} = undef unless
314 71 ▶ defined $v{$sf} and defined $cur->{val} and $v{$sf} eq $cur->{val};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v{$sf} and defined $cur->{"val"} and $v{$sf} eq $cur->{"val"} 58 13 71
Condition83%5/6
defined $v{$sf} and defined $cur->{"val"} and $v{$sf} eq $cur->{"val"}
!ll&&!rl&&r
253313
defined $v{$sf} and defined $cur->{"val"}
!ll&&!rl&&r
02546
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"}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
$cur->{'occ'} > 1 ? : 3 5 8
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
BranchTrueFalseTotal
unless (defined $self->{"fieldstat"}) 14 6 20
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
BranchTrueFalseTotal
if ($count{$tag}) { } 94 42 136
358 94 ▶ if ( $count{$tag} > 1 and $fieldstat->{$tag} < 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count{$tag} > 1 and $fieldstat->{$tag} < 2) 0 94 94
Condition66%2/3
$count{$tag} > 1 and $fieldstat->{$tag} < 2
!ll&&!rl&&r
9220
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
$fieldstat->{$tag} > 1 ? : 16 26 42
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
BranchTrueFalseTotal
$count{$tag} > 1 ? : 4 74 78
370 }
371 }
372  
373 13 1;
374  
375 __END__
↑ Summary SOAPClient.pm »