PICA/Parser/Import.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 88.2% 60 / 68 CC 11 SCAR 21.2
CC
11
Cov
87%
_next_record
11.6
BEGIN
1.0
BEGIN
1.0
CRAP 8.3
« PICA/Writer/Import.pm ↑ Summary PICA/Data.pm »
1 package PICA::Parser::Import;
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 8 ▶sub _next_record {
Subroutine _next_record: called CC=11 SCAR=24.5
13 8 my ($self) = @_;
14  
15 8 my $reader = $self->{reader};
16 8 my $line;
17  
18 # All data before the first record separator is ignored
19 8 ▶ if (!$self->count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->count) 6 2 8
20 6 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\x1D$/u and do { do { $line = readline $reader; return unless defined $line } } 0 6 6
21 6 $line = readline($reader);
22 6 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 6 6
23 } while ($line =~ /^\x1D$/);
24 }
25  
26 8 my @record;
27 8 while (1) {
28 70 $line = readline($reader);
29 70 ▶ if (!defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 2 68 70
30 2 ▶ @record ? last : return;
Branch: 1 branch
BranchTrueFalseTotal
@record ? : 1 1 2
31 }
32  
33 68 ▶ next if $line =~ /^#|^\s*$/; # ignore empty or comment lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^#|^\s*$/u 7 61 68
34 61 ▶ last if $line =~ /^\x1D$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\x1D$/u 6 55 61
35 55 chomp $line;
36  
37 55 ▶ if ($line
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ m[^\x1E([012][0-9][0-9][A-Z\@])(/(\d{2,3}))?\s((\x1F[^\x1F]+)+)$]u) { } 55 0 55
elsif ($self->{'strict'}) { } 0 0 0
38 =~ m/^\x1E([012][0-9][0-9][A-Z@])(\/(\d{2,3}))?\s((\x1F[^\x1F]+)+)$/
39 )
40 {
41 55 my $tag = $1;
42 55 ▶ my $occ = $3 > 0 ? $3 : '';
Branch: 1 branch
BranchTrueFalseTotal
$3 > 0 ? : 21 34 55
43 55 my @sf = split /\x1F/, $4;
44 55 shift @sf;
45 55 push @record, [$tag, $occ, map {split //, $_, 2} @sf];
46 }
47 elsif ($self->{strict}) {
48 0 croak "ERROR: invalid PICA field structure \"$line\"";
49 }
50 else {
51 0 carp
52 "WARNING: invalid PICA field structure \"$line\". Skipped field";
53 0 next;
54 }
55  
56 }
57  
58 7 return \@record;
59 }
60  
61 16 1;
62 __END__
« PICA/Writer/Import.pm ↑ Summary PICA/Data.pm »