blib/lib/PICA/Parser/Plain.pm

filter: Statementstmt 100% 69 / 69 Branchbran 100% 36 / 36 Conditioncond 100% 9 / 9 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 99.2% 127 / 128 CC 23 SCAR 29.1
CC
23
Cov
100%
_next_record
23.0
BEGIN
1.0
BEGIN
1.0
CRAP 18.4
« blib/lib/PICA/Writer/PIXML.pm ↑ Summary blib/lib/PICA/Writer/XML.pm »
1 package PICA::Parser::Plain;
2 16 ▶use v5.14.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 16 our $VERSION = '2.09';
6  
7 16 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 ▶use parent 'PICA::Parser::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 85 ▶sub END_OF_FIELD {"\N{LINE FEED}"}
Subroutine END_OF_FIELD: called CC=1 SCAR=0.0
Pod undocumented
13  
14 sub _next_record {
15 93 ▶ my ($self) = @_;
Subroutine _next_record: called CC=23 SCAR=31.4
16  
17 93 my $reader = $self->{reader};
18 93 my $plain;
19  
20 93 ▶ my $blank = $self->{strict} ? '\s*' : '((SET|Eingabe|Warnung):.*)?\s*';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'strict'} ? : 5 88 93
21 93 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
defined $plain and $plain =~ /^$blank$/u and do { do { $plain = readline $reader } } 1 93 94
Condition100%3/3
defined $plain and $plain =~ /^$blank$/u
!ll&&!rl&&r
8851
MC/DC100%2/2
defined $plain and $plain =~ /^$blank$/u
defined $plain $plain =~ /^$blank$/u
Truth table100%3/3
A and B
A= defined $plainB= $plain =~ /^$blank$/u
ABresult
0X0
100
111
22 94 $plain = readline($reader);
23 } while (defined $plain && $plain =~ /^$blank$/);
24  
25 93 ▶ while (defined(my $line = readline($reader))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $reader)) 6212 66 6278
26 6212 ▶ last if $line =~ /^$blank$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^$blank$/u 27 6185 6212
27 6185 $plain .= $line;
28 }
29 93 ▶ return unless defined $plain;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plain 8 85 93
30  
31 85 chomp $plain;
32 85 my @fields = split $self->END_OF_FIELD, $plain;
33 85 my @record;
34  
35 85 for my $field (@fields) {
36 6270 my ($annotation, $tag, $occ, $data);
37  
38 6270 ▶ unless (defined $self->{annotate} && !$self->{annotate}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"annotate"} and not $self->{"annotate"}) 6266 4 6270
Condition100%3/3
defined $self->{"annotate"} and not $self->{"annotate"}
!ll&&!rl&&r
626244
MC/DC100%2/2
defined $self->{"annotate"} and not $self->{"annotate"}
defined $self->{"annotate"} not $self->{"annotate"}
Truth table100%3/3
A and not(B)
A= defined $self->{"annotate"}B= not $self->{"annotate"}
ABresult
0X0
100
111
39 6266 ▶ if ($field =~ s/^([^a-z0-9]) (.+)/\2/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ s/^([^a-z0-9]) (.+)/$2/u) { } 12 6254 6266
elsif ($self->{'annotate'}) { } 2 6252 6254
40 12 $annotation = $1;
41 }
42 elsif ($self->{annotate}) {
43 2 croak "ERROR: expected field annotation at field \"$field\"";
44 }
45 }
46  
47 6268 ▶ if ($field =~ m/^(\d{3}[A-Z@])(\/(\d{2,3}))?\s(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ m[^(\d{3}[A-Z\@])(/(\d{2,3}))?\s(.+)]u) { } 6262 6 6268
48 6262 $tag = $1;
49 6262 $occ = $3;
50 6262 $data = $4;
51 }
52 else {
53 6 ▶ if ($self->{strict}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strict'}) { } 3 3 6
54 3 croak " ERROR : no valid PICA field structure \"$field\"";
55 }
56 else {
57 3 carp
58 "WARNING: no valid PICA field structure \"$field\". Skipped field";
59 next
60 3 }
61 }
62  
63 6262 ▶ if (!$self->{strict} && $data =~ /^ƒ/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"strict"} and $data =~ /^\x{192}/u) 2 6260 6262
Condition100%3/3
not $self->{"strict"} and $data =~ /^\x{192}/u
!ll&&!rl&&r
262582
MC/DC100%2/2
not $self->{"strict"} and $data =~ /^\x{192}/u
not $self->{"strict"} $data =~ /^\x{192}/u
Truth table100%3/3
not(A) and B
A= not $self->{"strict"}B= $data =~ /^\x{192}/u
ABresult
0X0
100
111
64 2 $data =~ s/\$/\$\$/g;
65 2 $data =~ s/ƒ/\$/g;
66 }
67  
68 6262 my @subfields = split /\$(\$+|.)/, $data;
69 6262 shift @subfields;
70 6262 ▶ push @subfields, '' if @subfields % 2; # last subfield without value
Branch: 1 branch
BranchTrueFalseTotal
if @subfields % 2 10 6252 6262
71  
72 6262 ▶ if ($data =~ /\$\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /\$\$/u) 6 6256 6262
73 6 my @tokens = (shift @subfields, shift @subfields);
74 6 ▶ while (@subfields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@subfields) 12 6 18
75 12 my $code = shift @subfields;
76 12 my $value = shift @subfields;
77 12 ▶ if ($code =~ /^\$+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^\$+$/u) 11 1 12
78 11 my $length = length $code;
79 11 $code =~ s/\$\$/\$/g;
80 11 ▶ if ($length % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length % 2) { } 1 10 11
81 1 $tokens[-1] .= "$code$value";
82 1 next;
83 }
84 else {
85 10 $tokens[-1] .= $code;
86 10 $code = substr $value, 0, 1;
87 10 $value = substr $value, 1;
88 }
89 }
90 11 push @tokens, $code, $value;
91 }
92 6 @subfields = @tokens;
93 }
94  
95 6262 ▶ push @subfields, $annotation if defined $annotation;
Branch: 1 branch
BranchTrueFalseTotal
if defined $annotation 12 6250 6262
96  
97 6262 ▶ push @record, [$tag, $occ > 0 ? $occ : '', @subfields];
Branch: 1 branch
BranchTrueFalseTotal
$occ > 0 ? : 5771 491 6262
98 }
99 80 return \@record;
100 }
101  
102 16 1;
103 __END__
« blib/lib/PICA/Writer/PIXML.pm ↑ Summary blib/lib/PICA/Writer/XML.pm »