blib/lib/POE/Filter/JSON.pm

filter: Statementstmt 67.9% 36 / 53 Branchbran 28.5% 4 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 5 totaltotal 56.3% 49 / 87 CC 11 SCAR 15.2
CC
11
Cov
59%
get_one
12.0
get_one_start
6.0
new
4.9
CRAP 4.6
↑ Summary
1 package POE::Filter::JSON;
2  
3 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use JSON::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base qw( POE::Filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.04';
12  
13 sub BUFFER () { 0 }
14 sub OBJ () { 1 }
15 sub PARAMS () { 2 }
16  
17 1 ▶sub new {
Subroutine new: called CC=4 SCAR=15.9
Pod undocumented
18 1 my $class = shift;
19 1 ▶ croak "$class requires an even number of parameters" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 1 1
20 1 my %opts = @_;
21 0 ▶ my %anyopts = ( $opts{json_any} ) ? %{$opts{json_any}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$opts{'json_any'} ? : 0 1 1
22 1 ▶ bless( [
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
23 [], # BUFFER
24 JSON::Any->new( %anyopts ), # OBJ
25 \%opts, # PARAMS
26 ], ref $class || $class );
27 }
28  
29 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.2
Pod undocumented
30 1 my ($self, $lines) = @_;
31 1 my $ret = [];
32  
33 1 foreach my $json (@$lines) {
34 1 ▶ if ( my $obj = eval { $self->[ OBJ ]->jsonToObj( $json ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = eval { do { $self->[1]->jsonToObj($json) } }) { } 1 0 1
35 1 push( @$ret, $obj );
36 } else {
37 0 warn "Couldn't convert json to an object: $@";
38 }
39 }
40 1 return $ret;
41 }
42  
43 0 ▶sub get_one_start {
Subroutine get_one_start: not called CC=2 SCAR=17.9
Pod undocumented
44 0 my ($self, $lines) = @_;
45 0 ▶ $lines = [ $lines ] unless ( ref( $lines ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lines 0 0 0
46 0 push( @{ $self->[ BUFFER ] }, @{ $lines } );
47 }
48  
49 0 ▶sub get_one {
Subroutine get_one: not called CC=3 SCAR=24.8
Pod undocumented
50 0 my $self = shift;
51 0 my $ret = [];
52  
53 0 ▶ if ( my $line = shift ( @{ $self->[ BUFFER ] } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @{$$self[0];}) 0 0 0
54 0 ▶ if ( my $json = eval { $self->[ OBJ ]->jsonToObj( $line ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $json = eval { do { $self->[1]->jsonToObj($line) } }) { } 0 0 0
55 0 push( @$ret, $json );
56 } else {
57 0 warn "Couldn't convert json to object: $@";
58 }
59 }
60  
61 0 return $ret;
62 }
63  
64 1 ▶sub put {
Subroutine put: called CC=3 SCAR=11.2
Pod undocumented
65 1 my ($self, $objects) = @_;
66 1 my $ret = [];
67  
68 1 foreach my $obj (@$objects) {
69 1 ▶ if ( my $json = eval { $self->[ OBJ ]->objToJson( $obj, $self->[ PARAMS ] ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $json = eval { do { $self->[1]->objToJson($obj, $self->[2]) } }) { } 1 0 1
70 1 push( @$ret, $json );
71 } else {
72 0 warn "Couldn't convert object to json\n";
73 }
74 }
75
76 1 return $ret;
77 }
78  
79 2 1;
80  
81 __END__
↑ Summary