| 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.12'; | |||||||||||||||||||||||||||
| 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 | 92 | ▶ | sub END_OF_FIELD {"\N{LINE FEED}"} | ||||||||||||||||||||||||||
|
Subroutine
END_OF_FIELD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 101 | ▶ | sub _next_record { | ||||||||||||||||||||||||||
|
Subroutine
_next_record: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 15 | 101 | my ($self) = @_; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 101 | my $reader = $self->{reader}; | |||||||||||||||||||||||||||
| 18 | 101 | my $plain; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 101 | ▶ | my $blank = $self->{strict} ? '\s*' : '((SET|Eingabe|Warnung):.*)?\s*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 101 | ▶ | 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 | 102 | $plain = readline($reader); | |||||||||||||||||||||||||||
| 23 | } while (defined $plain && $plain =~ /^$blank$/); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 101 | ▶ | while (defined(my $line = readline($reader))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 6232 | ▶ | last if $line =~ /^$blank$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 6204 | $plain .= $line; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 101 | ▶ | return unless defined $plain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 92 | chomp $plain; | |||||||||||||||||||||||||||
| 32 | 92 | my @fields = split $self->END_OF_FIELD, $plain; | |||||||||||||||||||||||||||
| 33 | 92 | my @record; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 92 | for my $field (@fields) { | |||||||||||||||||||||||||||
| 36 | 6296 | $field = $self->parse_field($field); | |||||||||||||||||||||||||||
| 37 | 6289 | ▶ | push @record, $field if $field; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 85 | return \@record; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6296 | ▶ | sub parse_field { | ||||||||||||||||||||||||||
|
Subroutine
parse_field: called CC=13 SCAR=25.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 6296 | my ($self, $field) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6296 | my ($annotation, $tag, $occ, $data); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 6296 | ▶ | 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"}
| |||||||||||||||||||||||||||||
| 49 | 6292 | ▶ | if ($field =~ s/^([^a-z0-9]) (.+)/\2/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 50 | 14 | $annotation = $1; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | elsif ($self->{annotate}) { | ||||||||||||||||||||||||||||
| 53 | 2 | croak "ERROR: expected field annotation at field \"$field\""; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6294 | ▶ | if ($field =~ m/^(\d{3}[A-Z@])(\/(\d{2,3}))?\s(.+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 6288 | $tag = $1; | |||||||||||||||||||||||||||
| 59 | 6288 | $occ = $3; | |||||||||||||||||||||||||||
| 60 | 6288 | $data = $4; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6294 | ▶ | 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 | 6294 | ▶ | if ($data !~ /^(\$[^\$]([^\$]|\$\$)*)+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 7 | ▶ | if ($self->{strict}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 4 | croak "ERROR: invalid PICA field structure \"$field\""; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 3 | carp | |||||||||||||||||||||||||||
| 74 | "WARNING: invalid PICA field structure \"$field\". Skipped field"; | ||||||||||||||||||||||||||||
| 75 | 3 | return; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 6287 | my @subfields; | |||||||||||||||||||||||||||
| 80 | 6287 | ▶ | while ($data =~ m/\G\$([^\$])(([^\$]|\$\$)*)/g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 13784 | my ($code, $value) = ($1, $2); | |||||||||||||||||||||||||||
| 82 | 13784 | $value =~ s/\$\$/\$/g; | |||||||||||||||||||||||||||
| 83 | 13784 | push @subfields, $code, $value; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 6287 | ▶ | push @subfields, $annotation if defined $annotation; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 6287 | ▶ | return [$tag, $occ > 0 ? $occ : '', @subfields]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 16 | 1; | |||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||