| 1 | package PICA::Parser::Plus; | ||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 16 | our $VERSION = '2.12'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use charnames qw(:full); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use parent 'PICA::Parser::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 66 | ▶ | sub SUBFIELD_INDICATOR {"\N{INFORMATION SEPARATOR ONE}"} | ||||||||||||||||||||||||||
|
Subroutine
SUBFIELD_INDICATOR: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | sub END_OF_FIELD {"\N{INFORMATION SEPARATOR TWO}"} | ||||||||||||||||||||||||||
|
Subroutine
END_OF_FIELD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 10 | ▶ | sub END_OF_RECORD {"\N{LINE FEED}"} | ||||||||||||||||||||||||||
|
Subroutine
END_OF_RECORD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 19 | ▶ | sub _next_record { | ||||||||||||||||||||||||||
|
Subroutine
_next_record: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 16 | 19 | my ($self) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # TODO: does only work if END_OF_RECORD is LINE FEED | ||||||||||||||||||||||||||||
| 19 | 19 | local $/ = $self->END_OF_RECORD; | |||||||||||||||||||||||||||
| 20 | 19 | ▶ | my $line = $self->{reader}->getline // return; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"reader"}->getline // (return)
MC/DC100%1/1
$self->{"reader"}->getline // (return)
$self->{"reader"}->getline
Truth table100%2/2
A
A= $self->{"reader"}->getline
| |||||||||||||||||||||||||||||
| 21 | 16 | chomp $line; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 16 | my @fields = split $self->END_OF_FIELD, $line; | |||||||||||||||||||||||||||
| 24 | 16 | my @record; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 16 | ▶ | if (@fields and index($fields[0], $self->SUBFIELD_INDICATOR) == -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@fields and index($fields[0], $self->SUBFIELD_INDICATOR) == -1
MC/DC100%2/2
@fields and index($fields[0], $self->SUBFIELD_INDICATOR) == -1
@fields
index($fields[0], $self->SUBFIELD_INDICATOR) == -1
Truth table100%3/3
A and B
A= @fieldsB= index($fields[0], $self->SUBFIELD_INDICATOR) == -1
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # drop leader because usage is unclear | ||||||||||||||||||||||||||||
| 29 | 8 | shift @fields; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 16 | foreach my $field (@fields) { | |||||||||||||||||||||||||||
| 33 | 118 | my ($tag, $occ, $data); | |||||||||||||||||||||||||||
| 34 | 118 | ▶ | if ($field =~ m/^(\d{3}[A-Z@])(\/(\d{2,3}))?\s(.+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 114 | $tag = $1; | |||||||||||||||||||||||||||
| 36 | 114 | $occ = $3; | |||||||||||||||||||||||||||
| 37 | 114 | $data = $4; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||
| 40 | 4 | ▶ | if ($self->{strict}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 1 | croak "ERROR: invalid PICA field structure \"$field\""; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||
| 44 | 3 | carp | |||||||||||||||||||||||||||
| 45 | "WARNING: invalid PICA field structure \"$field\". Skipped field"; | ||||||||||||||||||||||||||||
| 46 | 3 | next; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 114 | my @subfields = map {substr($_, 0, 1), substr($_, 1)} | |||||||||||||||||||||||||||
| 51 | split($self->SUBFIELD_INDICATOR, substr($data, 1)); | ||||||||||||||||||||||||||||
| 52 | 114 | ▶ | push @record, [$tag, $occ > 0 ? $occ : '', @subfields]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 15 | return \@record; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 16 | 1; | |||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||