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.46';
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 override 'parse' => sub {
10 0 ▶ my ($self, $raw) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
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__
47  
48 =pod
49  
50 =encoding UTF-8
51  
52 =head1 NAME
53  
54 MARC::Moose::Parser::Json - Parser for JSON records
55  
56 =head1 VERSION
57  
58 version 1.0.46
59  
60 =head1 SEE ALSO
61 =for :list
62 * L<MARC::Moose>
63 * L<MARC::Moose::Parser>
64  
65 =head1 AUTHOR
66  
67 Frédéric Demians <f.demians@tamil.fr>
68  
69 =head1 COPYRIGHT AND LICENSE
70  
71 This software is copyright (c) 2022 by Frédéric Demians.
72  
73 This is free software; you can redistribute it and/or modify it under
74 the same terms as the Perl 5 programming language system itself.
75  
76 =cut
« Moose/Formater/Legacy.pm ↑ Summary Moose/Parser/Legacy.pm »