Moose/Parser/Json.pm

filter: Statementstmt 34.3% 11 / 32 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 28.8% 13 / 45 CC 6 SCAR 34.6
CC
6
Cov
26%
__ANON__
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 31.8
« Moose/Formater/Legacy.pm ↑ Summary Moose/Parser/Legacy.pm »
1 package MARC::Moose::Parser::Json;
2 # ABSTRACT: Parser for JSON records
3 4 $MARC::Moose::Parser::Json::VERSION = '1.0.49';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends 'MARC::Moose::Parser';
6 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 0 ▶override 'parse' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
10 0 my ($self, $raw) = @_;
11 0 ▶ return unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 0 0 0
12 0 my $json = from_json($raw);
13 0 my @jfields = @{$json->{fields}};
14 0 my @fields;
15 0 ▶ while ( @jfields ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@jfields) 0 0 0
16 0 my $tag = shift @jfields;
17 0 my $value = shift @jfields;
18 0 ▶ if ( ref($value) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'HASH') { } 0 0 0
19 0 my @subf;
20 0 my @jsubf = @{$value->{subfields}};
21 0 ▶ while (@jsubf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@jsubf) 0 0 0
22 0 my ($letter, $value) = (shift @jsubf, shift @jsubf);
23 0 push @subf, [ $letter => $value ];
24 }
25 push @fields, MARC::Moose::Field::Std->new(
26 tag => $tag,
27 ind1 => $value->{ind1},
28 ind2 => $value->{ind2},
29 0 subf => \@subf );
30 }
31 else {
32 0 push @fields, MARC::Moose::Field::Control->new(
33 tag => $tag, value => $value );
34 }
35 }
36 my $record = MARC::Moose::Record->new(
37 leader => $json->{leader},
38 0 fields => \@fields );
39 0 ▶ $record->lint($self->lint) if $record->lint;
Branch: 1 branch
BranchTrueFalseTotal
if $record->lint 0 0 0
40 0 return $record;
41 4 };
42  
43 4 __PACKAGE__->meta->make_immutable;
44 4 1;
45  
46 __END__
« Moose/Formater/Legacy.pm ↑ Summary Moose/Parser/Legacy.pm »