| 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
| |||||||||||||||||||||||||||||
| 21 | 93 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $plain and $plain =~ /^$blank$/u
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
| |||||||||||||||||||||||||||||
| 22 | 94 | $plain = readline($reader); | |||||||||||||||||||||||||||
| 23 | } while (defined $plain && $plain =~ /^$blank$/); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 93 | ▶ | while (defined(my $line = readline($reader))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 6212 | ▶ | last if $line =~ /^$blank$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 6185 | $plain .= $line; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 93 | ▶ | return unless defined $plain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $self->{"annotate"} and not $self->{"annotate"}
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"}
| |||||||||||||||||||||||||||||
| 39 | 6266 | ▶ | if ($field =~ s/^([^a-z0-9]) (.+)/\2/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 48 | 6262 | $tag = $1; | |||||||||||||||||||||||||||
| 49 | 6262 | $occ = $3; | |||||||||||||||||||||||||||
| 50 | 6262 | $data = $4; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||
| 53 | 6 | ▶ | if ($self->{strict}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 6262 | ▶ | if ($data =~ /\$\$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 6 | my @tokens = (shift @subfields, shift @subfields); | |||||||||||||||||||||||||||
| 74 | 6 | ▶ | while (@subfields) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 12 | my $code = shift @subfields; | |||||||||||||||||||||||||||
| 76 | 12 | my $value = shift @subfields; | |||||||||||||||||||||||||||
| 77 | 12 | ▶ | if ($code =~ /^\$+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 11 | my $length = length $code; | |||||||||||||||||||||||||||
| 79 | 11 | $code =~ s/\$\$/\$/g; | |||||||||||||||||||||||||||
| 80 | 11 | ▶ | if ($length % 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 6262 | ▶ | push @record, [$tag, $occ > 0 ? $occ : '', @subfields]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 80 | return \@record; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 16 | 1; | |||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||