| 1 | package PICA::Parser::Base; | ||||||||||||||||||||||||||||||||||||||||
| 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 PICA::Data::Field; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | use Encode qw(encode); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | 121 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||
| 12 | 121 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||
| 13 | 121 | ▶ | my (%options) = @_ % 2 ? (fh => @_) : @_; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||
| 15 | bless { | ||||||||||||||||||||||||||||||||||||||||
| 16 | strict => !!$options{strict}, | ||||||||||||||||||||||||||||||||||||||||
| 17 | fh => defined $options{fh} ? $options{fh} : \*STDIN, | ||||||||||||||||||||||||||||||||||||||||
| 18 | annotate => $options{annotate}, | ||||||||||||||||||||||||||||||||||||||||
| 19 | 121 | ▶ | counter => 0, | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 20 | }, $class; | ||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | 107 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 107 | my $self = _new(@_); | |||||||||||||||||||||||||||||||||||||||
| 25 | 107 | my $input = $self->{fh}; | |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||
| 27 | # check for file or filehandle | ||||||||||||||||||||||||||||||||||||||||
| 28 | 107 | my $ishandle = eval {fileno($input);}; | |||||||||||||||||||||||||||||||||||||||
| 29 | 107 | ▶ | if (!$@ && defined $ishandle) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
not $@ and defined $ishandle
MC/DC100%2/2
not $@ and defined $ishandle
not $@
defined $ishandle
Truth table100%3/3
not(A) and B
A= not $@B= defined $ishandle
| |||||||||||||||||||||||||||||||||||||||||
| 30 | 5 | $self->{reader} = $input; | |||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||
| 32 | ▶ | elsif ($input !~ /\n/ and -e $input) { | |||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $input =~ /\n/u and -e $input
MC/DC100%2/2
not $input =~ /\n/u and -e $input
not $input =~ /\n/u
-e $input
Truth table100%3/3
not(A) and B
A= not $input =~ /\n/uB= -e $input
| |||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", $input) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 34 | or croak "Failed to read from file $input\n"; | ||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||
| 36 | ▶ | elsif ((ref $input and reftype $input eq 'SCALAR')) { | |||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
ref $input and builtin::reftype($input) eq "SCALAR"
MC/DC100%2/2
ref $input and builtin::reftype($input) eq "SCALAR"
ref $input
builtin::reftype($input) eq "SCALAR"
Truth table100%3/3
A and B
A= ref $inputB= builtin::reftype($input) eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||
| 37 | 84 | $input = encode('UTF-8', $$input); | |||||||||||||||||||||||||||||||||||||||
| 38 | 84 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", \$input) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 39 | or croak "Failed to read from string reference\n"; | ||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||
| 41 | elsif ($input =~ /\n/) { | ||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | $input = encode('UTF-8', $input); | |||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", \$input) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 44 | or croak "Failed to read from string\n"; | ||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | croak "file or filehandle $input does not exists"; | |||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | 105 | $self; | |||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | 24 | ▶ | sub count { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 54 | 24 | return $_[0]->{counter}; | |||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||
| 57 | 146 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 58 | 146 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | 146 | ▶ | while (my $record = $self->_next_record) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 61 | 133 | ▶ | next unless @$record; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 62 | 121 | $self->{counter}++; | |||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | # get last 003@ $0 as _id (TODO: _id for level 1 and 2?) | ||||||||||||||||||||||||||||||||||||||||
| 65 | 121 | my $id; | |||||||||||||||||||||||||||||||||||||||
| 66 | 121 | ▶ | if (my ($field) = grep {($_->[0] // '') =~ '003@'} @$record) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$_->[0] // ""
MC/DC0%0/1
$_->[0] // ""
$_->[0]
Truth table50%1/2
A
A= $_->[0]
| |||||||||||||||||||||||||||||||||||||||||
| 67 | 53 | ▶ | for (my $i = 2; $i < @$field; $i += 2) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 68 | 53 | ▶ | if ($field->[$i] eq '0') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 69 | 53 | $id = $field->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||
| 70 | 53 | last; | |||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||
| 75 | 121 | my @fields = map {bless $_, 'PICA::Data::Field'} @$record; | |||||||||||||||||||||||||||||||||||||||
| 76 | 121 | return bless {record => \@fields, _id => $id}, 'PICA::Data'; | |||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||
| 79 | 17 | return; | |||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub all { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
all: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my @records; | |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | while (my $record = $self->next) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | push @records, $record; | |||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | return \@records; | |||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||
| 93 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||||||||||||||