blib/lib/POE/Filter/JSONMaybeXS.pm

filter: Statementstmt 69.2% 36 / 52 Branchbran 25.0% 3 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 100% 5 / 5 totaltotal 63.1% 53 / 84 CC 10 SCAR 14.6
CC
10
Cov
60%
get_one
12.0
get_one_start
6.0
new
3.3
CRAP 4.3
↑ Summary
1 package POE::Filter::JSONMaybeXS;
2 2 our $AUTHORITY = 'cpan:GETTY';
3 # ABSTRACT: A POE filter using JSON::MaybeXS
4 2 $POE::Filter::JSONMaybeXS::VERSION = '0.002';
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use base qw( POE::Filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub BUFFER () { 0 }
14 sub OBJ () { 1 }
15  
16 1 ▶sub new {
Subroutine new: called CC=3 SCAR=12.0
Pod documented
17 1 my $class = shift;
18 1 ▶ croak "$class requires an even number of parameters" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 1 1
19 1 my %opts = @_;
20 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
21 [], # BUFFER
22 JSON::MaybeXS->new( %opts ) # OBJ
23 ], ref $class || $class );
24 }
25  
26 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.2
Pod documented
27 1 my ($self, $lines) = @_;
28 1 my $ret = [];
29  
30 1 foreach my $json (@$lines) {
31 1 ▶ if ( my $data = eval { ($self->[ OBJ ]->decode( $json )) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = eval { do { $self->[1]->decode($json) } }) { } 1 0 1
32 1 push( @$ret, $data );
33 } else {
34 0 warn "Couldn't convert json: $@";
35 }
36 }
37 1 return $ret;
38 }
39  
40 0 ▶sub get_one_start {
Subroutine get_one_start: not called CC=2 SCAR=17.9
Pod documented
41 0 my ($self, $lines) = @_;
42 0 ▶ $lines = [ $lines ] unless ( ref( $lines ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $lines 0 0 0
43 0 push( @{ $self->[ BUFFER ] }, @{ $lines } );
44 }
45  
46 0 ▶sub get_one {
Subroutine get_one: not called CC=3 SCAR=24.8
Pod documented
47 0 my $self = shift;
48 0 my $ret = [];
49  
50 0 ▶ if ( my $line = shift ( @{ $self->[ BUFFER ] } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @{$$self[0];}) 0 0 0
51 0 ▶ if ( my $data = eval { ($self->[ OBJ ]->decode( $line )) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = eval { do { $self->[1]->decode($line) } }) { } 0 0 0
52 0 push( @$ret, $data );
53 } else {
54 0 warn "Couldn't convert json: $@";
55 }
56 }
57  
58 0 return $ret;
59 }
60  
61 1 ▶sub put {
Subroutine put: called CC=3 SCAR=11.2
Pod documented
62 1 my ($self, $objects) = @_;
63 1 my $ret = [];
64  
65 1 foreach my $obj (@$objects) {
66 1 ▶ if ( my $json = eval { $self->[ OBJ ]->encode( $obj ) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $json = eval { do { $self->[1]->encode($obj) } }) { } 1 0 1
67 1 push( @$ret, $json );
68 } else {
69 0 warn "Couldn't convert object to json\n";
70 }
71 }
72
73 1 return $ret;
74 }
75  
76 2 1;
77  
78 __END__
↑ Summary