| 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
| |||||||||||||||||||||
| 19 | 1 | my %opts = @_; | |||||||||||||||||||
| 20 | 1 | ▶ | bless( [ | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 51 | 0 | ▶ | if ( my $data = eval { ($self->[ OBJ ]->decode( $line )) } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||