| 1 | package PICA::Parser::Base; | ||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use v5.14.1; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | our $VERSION = '1.18'; | |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use Encode qw(encode); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||
| 10 | sub _new { | ||||||||||||||||||||||||||||||||||||||||
| 11 | 59 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||
| 12 | 59 | ▶ | my (%options) = @_ % 2 ? (fh => @_) : @_; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||
| 14 | bless { | ||||||||||||||||||||||||||||||||||||||||
| 15 | bless => !!$options{bless}, | ||||||||||||||||||||||||||||||||||||||||
| 16 | strict => !!$options{strict}, | ||||||||||||||||||||||||||||||||||||||||
| 17 | fh => defined $options{fh} ? $options{fh} : \*STDIN, | ||||||||||||||||||||||||||||||||||||||||
| 18 | annotated => $options{annotated} | ||||||||||||||||||||||||||||||||||||||||
| 19 | 59 | ▶ | }, $class; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 23 | 48 | ▶ | my $self = _new(@_); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 48 | my $input = $self->{fh}; | |||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | # check for file or filehandle | ||||||||||||||||||||||||||||||||||||||||
| 27 | 48 | my $ishandle = eval {fileno($input);}; | |||||||||||||||||||||||||||||||||||||||
| 28 | 48 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | $self->{reader} = $input; | |||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||
| 31 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||
| 32 | 8 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", $input) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 33 | or croak "Failed to read from file $input\n"; | ||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||
| 35 | ▶ | 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"
| |||||||||||||||||||||||||||||||||||||||||
| 36 | 32 | $input = encode('UTF-8', $$input); | |||||||||||||||||||||||||||||||||||||||
| 37 | 32 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", \$input) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 38 | or croak "Failed to read from string reference\n"; | ||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||
| 40 | elsif ($input =~ /\n/) { | ||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | $input = encode('UTF-8', $input); | |||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | open($self->{reader}, "<:encoding(UTF-8)", \$input) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 43 | or croak "Failed to read from string\n"; | ||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | croak "file or filehandle $input does not exists"; | |||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | 46 | $self; | |||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | sub next { | ||||||||||||||||||||||||||||||||||||||||
| 53 | 74 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||
| 55 | # get last subfield from 003@ as id | ||||||||||||||||||||||||||||||||||||||||
| 56 | 74 | ▶ | while (my $record = $self->_next_record) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 57 | 69 | ▶ | next unless @$record; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 58 | 60 | ▶ | my ($id) = map {$_->[-1]} grep {($_->[0] // '') =~ '003@'} @$record; | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_->[0] // ""
MC/DC0%0/1
$_->[0] // ""
$_->[0]
Truth table50%1/2
A
A= $_->[0]
| |||||||||||||||||||||||||||||||||||||||||
| 59 | 60 | $record = {_id => $id, record => $record}; | |||||||||||||||||||||||||||||||||||||||
| 60 | 60 | ▶ | bless $record, 'PICA::Data' if $self->{bless}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 61 | 60 | return $record; | |||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | return; | |||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||||||||