blib/lib/PICA/Parser/Plain.pm

filter: Statementstmt 100% 66 / 66 Branchbran 100% 30 / 30 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 99.1% 116 / 117 CC 20 SCAR 27.5
CC
20
Cov
100%
_next_record
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 15.6
« blib/lib/PICA/Writer/XML.pm ↑ Summary blib/lib/PICA/Writer/Base.pm »
1 package PICA::Parser::Plain;
2 8 ▶use v5.14.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 8 our $VERSION = '1.18';
6  
7 8 ▶use charnames ':full';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶use parent 'PICA::Parser::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 41 ▶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 43 ▶ my ($self) = @_;
Subroutine _next_record: called CC=20 SCAR=30.0
16  
17 43 my $plain = undef;
18 43 my $reader = $self->{reader};
19 43 ▶ while (my $line = <$reader>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $reader)) 6223 21 6244
20 6223 ▶ last if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/u 22 6201 6223
21 6201 $plain .= $line;
22 }
23 43 ▶ return unless defined $plain;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plain 2 41 43
24  
25 41 chomp $plain;
26 41 my @fields = split $self->END_OF_FIELD, $plain;
27 41 my @record;
28  
29 41 for my $field (@fields) {
30 6201 my ($annotation, $tag, $occurence, $data);
31  
32 6201 ▶ unless (defined $self->{annotated} && !$self->{annotated}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"annotated"} and not $self->{"annotated"}) 6197 4 6201
Condition100%3/3
defined $self->{"annotated"} and not $self->{"annotated"}
!ll&&!rl&&r
619344
MC/DC100%2/2
defined $self->{"annotated"} and not $self->{"annotated"}
defined $self->{"annotated"} not $self->{"annotated"}
Truth table100%3/3
A and not(B)
A= defined $self->{"annotated"}B= not $self->{"annotated"}
ABresult
0X0
100
111
33 6197 ▶ if ($field =~ s/^([^a-z0-9]) (.+)/\2/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ s/^([^a-z0-9]) (.+)/$2/u) { } 4 6193 6197
elsif ($self->{'annotated'}) { } 2 6191 6193
34 4 $annotation = $1;
35 }
36 elsif ($self->{annotated}) {
37 2 croak "ERROR: expected field annotation at field \"$field\"";
38 }
39 }
40  
41 6199 ▶ 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) { } 6193 6 6199
42 6193 $tag = $1;
43 6193 ▶ $occurence = $3 // '';
Condition100%2/2
$3 // ""
l!l
5763430
MC/DC100%1/1
$3 // ""
$3
Truth table100%2/2
A
A= $3
Aresult
11
00
44 6193 $data = $4;
45 }
46 else {
47 6 ▶ if ($self->{strict}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strict'}) { } 3 3 6
48 3 croak " ERROR : no valid PICA field structure \"$field\"";
49 }
50 else {
51 3 carp
52 "WARNING: no valid PICA field structure \"$field\". Skipped field";
53 next
54 3 }
55 }
56  
57 6193 ▶ if (!$self->{strict} && $data =~ /^ƒ/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"strict"} and $data =~ /^\x{192}/u) 2 6191 6193
Condition100%3/3
not $self->{"strict"} and $data =~ /^\x{192}/u
!ll&&!rl&&r
261892
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
58 2 $data =~ s/\$/\$\$/g;
59 2 $data =~ s/ƒ/\$/g;
60 }
61  
62 6193 my @subfields = split /\$(\$+|.)/, $data;
63 6193 shift @subfields;
64 6193 ▶ push @subfields, '' if @subfields % 2; # last subfield without value
Branch: 1 branch
BranchTrueFalseTotal
if @subfields % 2 10 6183 6193
65  
66 6193 ▶ if ($data =~ /\$\$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /\$\$/u) 6 6187 6193
67 6 my @tokens = (shift @subfields, shift @subfields);
68 6 ▶ while (@subfields) {
Branch: 1 branch
BranchTrueFalseTotal
if (@subfields) 12 6 18
69 12 my $code = shift @subfields;
70 12 my $value = shift @subfields;
71 12 ▶ if ($code =~ /^\$+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /^\$+$/u) 11 1 12
72 11 my $length = length $code;
73 11 $code =~ s/\$\$/\$/g;
74 11 ▶ if ($length % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length % 2) { } 1 10 11
75 1 $tokens[-1] .= "$code$value";
76 1 next;
77 }
78 else {
79 10 $tokens[-1] .= $code;
80 10 $code = substr $value, 0, 1;
81 10 $value = substr $value, 1;
82 }
83 }
84 11 push @tokens, $code, $value;
85 }
86 6 @subfields = @tokens;
87 }
88  
89 6193 ▶ push @subfields, $annotation if defined $annotation;
Branch: 1 branch
BranchTrueFalseTotal
if defined $annotation 4 6189 6193
90  
91 6193 push @record, [$tag, $occurence, @subfields];
92 }
93 36 return \@record;
94 }
95  
96 8 1;
97 __END__
« blib/lib/PICA/Writer/XML.pm ↑ Summary blib/lib/PICA/Writer/Base.pm »