| 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
| |||||||||||||||||||||||||||||
| 20 | 6223 | ▶ | last if $line =~ /^\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 6201 | $plain .= $line; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 43 | ▶ | return unless defined $plain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $self->{"annotated"} and not $self->{"annotated"}
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"}
| |||||||||||||||||||||||||||||
| 33 | 6197 | ▶ | if ($field =~ s/^([^a-z0-9]) (.+)/\2/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 6193 | $tag = $1; | |||||||||||||||||||||||||||
| 43 | 6193 | ▶ | $occurence = $3 // ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$3 // ""
MC/DC100%1/1
$3 // ""
$3
Truth table100%2/2
A
A= $3
| |||||||||||||||||||||||||||||
| 44 | 6193 | $data = $4; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||
| 47 | 6 | ▶ | if ($self->{strict}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $self->{"strict"} and $data =~ /^\x{192}/u
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 6193 | ▶ | if ($data =~ /\$\$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 6 | my @tokens = (shift @subfields, shift @subfields); | |||||||||||||||||||||||||||
| 68 | 6 | ▶ | while (@subfields) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 12 | my $code = shift @subfields; | |||||||||||||||||||||||||||
| 70 | 12 | my $value = shift @subfields; | |||||||||||||||||||||||||||
| 71 | 12 | ▶ | if ($code =~ /^\$+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 11 | my $length = length $code; | |||||||||||||||||||||||||||
| 73 | 11 | $code =~ s/\$\$/\$/g; | |||||||||||||||||||||||||||
| 74 | 11 | ▶ | if ($length % 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 6193 | push @record, [$tag, $occurence, @subfields]; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 36 | return \@record; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 8 | 1; | |||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||