blib/lib/MARC/File/JSON.pm

filter: Statementstmt 97.7% 44 / 45 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 14 / 14 Podpod 25.0% 1 / 4 totaltotal 89.1% 66 / 74 CC 5 SCAR 5.9
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 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use JSON qw(to_json from_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON::Streaming::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MARC::Record::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use MARC::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use MARC::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use vars qw( @ISA $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 $VERSION = '0.005';
16 2 push @ISA, 'MARC::File';
17  
18 # MARC::Record -> JSON
19 1 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod undocumented
20 1 my ($record, $args) = @_;
21 1 return to_json( $record->as_generic, $args );
22 }
23  
24 # JSON -> MARC::Record
25 12 ▶sub decode {
Subroutine decode: called CC=2 SCAR=7.6
Pod documented
26 12 my ($self, $data, $args) = @_;
27  
28 12 ▶ if ( !ref($data) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 0 12 12
29 0 $data = from_json( $data, $args );
30 }
31 12 return MARC::Record->new_from_generic( $data );
32 }
33  
34 12 ▶sub _next {
Subroutine _next: called CC=4 SCAR=13.9
35 12 my $self = shift;
36 my $jsonr
37 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
38 12 my $token = $jsonr->get_token;
39 12 ▶ if ($token->[0] eq 'start_array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[0] eq "start_array") 1 11 12
40 1 $token = $jsonr->get_token;
41 }
42 12 ▶ return ($token->[0] eq 'end_array') ? undef : $jsonr->slurp;
Branch: 1 branch
BranchTrueFalseTotal
$token->[0] eq 'end_array' ? : 1 11 12
43 }
44  
45 ### Methods injected into MARC::Record
46  
47 1 ▶sub MARC::Record::new_from_json {
Subroutine new_from_json: called CC=1 SCAR=0.0
Pod undocumented
48 1 my ($class, $json, $args) = @_;
49 1 return __PACKAGE__->decode( from_json($json, $args) );
50 }
51  
52 1 ▶sub MARC::Record::as_json {
Subroutine as_json: called CC=1 SCAR=0.0
Pod undocumented
53 1 my ($self, $args) = @_;
54 1 return encode( $self, $args );
55 }
56  
57 2 1;
58  
59 __END__
↑ Summary