| 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
| |||||||||||||||||||||
| 20 | 1 | my %opts = @_; | |||||||||||||||||||
| 21 | 0 | ▶ | my %anyopts = ( $opts{json_any} ) ? %{$opts{json_any}} : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 54 | 0 | ▶ | if ( my $json = eval { $self->[ OBJ ]->jsonToObj( $line ) } ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||