blib/lib/MARC/File/JSON.pm

filter: Statementstmt 97.6% 42 / 43 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 25.0% 1 / 4 totaltotal 88.7% 63 / 71 CC 5 SCAR 6.1
CC
5
Cov
94%
_next
4.0
decode
2.1
BEGIN
1.0
CRAP 1.8
↑ Summary
1 package MARC::File::JSON;
2  
3 # ABSTRACT: read/write MARC data into JSON format
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON qw(to_json from_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON::Streaming::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MARC::Record::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MARC::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MARC::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use vars qw( @ISA $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 $VERSION = '0.003';
15 2 push @ISA, 'MARC::File';
16  
17 # MARC::Record -> JSON
18 sub encode {
19 1 ▶ my ($record, $args) = @_;
Subroutine encode: called CC=1 SCAR=0.0
Pod undocumented
20 1 return to_json( $record->as_generic, $args );
21 }
22  
23 # JSON -> MARC::Record
24 sub decode {
25 12 ▶ my ($self, $data, $args) = @_;
Subroutine decode: called CC=2 SCAR=7.6
Pod documented
26  
27 12 ▶ if ( !ref($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 0 12 12
28 0 $data = from_json( $data, $args );
29 }
30 12 return MARC::Record->new_from_generic( $data );
31 }
32  
33 sub _next {
34 12 ▶ my $self = shift;
Subroutine _next: called CC=4 SCAR=13.9
35 my $jsonr
36 12 ▶ = $self->{jsonr} //= JSON::Streaming::Reader->for_stream($self->{fh});
Condition66%2/3
$self->{"jsonr"} //= "JSON::Streaming::Reader"->for_stream($self->{"fh"})
l!l&&r!l&&!r
1110
MC/DC0%0/2
$self->{"jsonr"} //= "JSON::Streaming::Reader"->for_stream($self->{"fh"})
$self->{"jsonr"} "JSON::Streaming::Reader"->for_stream($self->{"fh"})
Truth table66%2/3
A //= B
A= $self->{"jsonr"}B= "JSON::Streaming::Reader"->for_stream($self->{"fh"})
ABresult
1X1
011
000
37 12 my $token = $jsonr->get_token;
38 12 ▶ if ($token->[0] eq 'start_array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[0] eq "start_array") 1 11 12
39 1 $token = $jsonr->get_token;
40 }
41 12 ▶ return ($token->[0] eq 'end_array') ? undef : $jsonr->slurp;
Branch: 1 branch
BranchTrueFalseTotal
$token->[0] eq 'end_array' ? : 1 11 12
42 }
43  
44 ### Methods injected into MARC::Record
45  
46 sub MARC::Record::new_from_json {
47 1 ▶ my ($class, $json, $args) = @_;
Subroutine new_from_json: called CC=1 SCAR=0.0
Pod undocumented
48 1 return __PACKAGE__->decode( from_json($json, $args) );
49 }
50  
51 sub MARC::Record::as_json {
52 1 ▶ my ($self, $args) = @_;
Subroutine as_json: called CC=1 SCAR=0.0
Pod undocumented
53 1 return encode( $self, $args );
54 }
55  
56 2 1;
57  
58 __END__
↑ Summary