blib/lib/PICA/Parser/Base.pm

filter: Statementstmt 100% 42 / 42 Branchbran 83.3% 20 / 24 Conditioncond 90.9% 10 / 11 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 93.6% 88 / 94 CC 17 SCAR 18.7
CC
17
Cov
94%
new
11.1
next
5.0
_new
3.0
CRAP 6.5
« blib/lib/PICA/Data.pm ↑ Summary blib/lib/PICA/Error.pm »
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
BranchTrueFalseTotal
@_ % 2 ? : 44 15 59
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
BranchTrueFalseTotal
defined $options{'fh'} ? : 59 0 59
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
BranchTrueFalseTotal
if (not $@ and defined $ishandle) { } 4 44 48
elsif (not $input =~ /\n/u and -e $input) { } 8 36 44
elsif (ref $input and builtin::reftype($input) eq 'SCALAR') { } 32 4 36
elsif ($input =~ /\n/u) { } 2 2 4
Condition100%3/3
not $@ and defined $ishandle
!ll&&!rl&&r
34104
MC/DC100%2/2
not $@ and defined $ishandle
not $@ defined $ishandle
Truth table100%3/3
not(A) and B
A= not $@B= defined $ishandle
ABresult
0X0
100
111
29 4 $self->{reader} = $input;
30 }
31 ▶ elsif ($input !~ /\n/ and -e $input) {
Condition100%3/3
not $input =~ /\n/u and -e $input
!ll&&!rl&&r
2348
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
ABresult
0X0
100
111
32 8 ▶ open($self->{reader}, "<:encoding(UTF-8)", $input)
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"reader"}, "<:encoding(UTF-8)", $input or croak("Failed to read from file $input\n") 0 8 8
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"
!ll&&!rl&&r
2232
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"
ABresult
0X0
100
111
36 32 $input = encode('UTF-8', $$input);
37 32 ▶ open($self->{reader}, "<:encoding(UTF-8)", \$input)
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"reader"}, "<:encoding(UTF-8)", \$input or croak("Failed to read from string reference\n") 0 32 32
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
BranchTrueFalseTotal
open $self->{"reader"}, "<:encoding(UTF-8)", \$input or croak("Failed to read from string\n") 0 2 2
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
BranchTrueFalseTotal
if (my $record = $self->_next_record) 69 8 77
57 69 ▶ next unless @$record;
Branch: 1 branch
BranchTrueFalseTotal
unless @$record 9 60 69
58 60 ▶ my ($id) = map {$_->[-1]} grep {($_->[0] // '') =~ '003@'} @$record;
Condition50%1/2
$_->[0] // ""
l!l
64760
MC/DC0%0/1
$_->[0] // ""
$_->[0]
Truth table50%1/2
A
A= $_->[0]
Aresult
11
00
59 60 $record = {_id => $id, record => $record};
60 60 ▶ bless $record, 'PICA::Data' if $self->{bless};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"bless"} 9 51 60
61 60 return $record;
62 }
63  
64 8 return;
65 }
66  
67 8 1;
68 __END__
« blib/lib/PICA/Data.pm ↑ Summary blib/lib/PICA/Error.pm »