line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Filter::JSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
46156
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
213
|
|
4
|
2
|
|
|
2
|
|
2077
|
use JSON::Any; |
|
2
|
|
|
|
|
65319
|
|
|
2
|
|
|
|
|
16
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
18211
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
65
|
|
7
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use base qw( POE::Filter ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1866
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub BUFFER () { 0 } |
14
|
|
|
|
|
|
|
sub OBJ () { 1 } |
15
|
|
|
|
|
|
|
sub PARAMS () { 2 } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
1
|
16
|
my $class = shift; |
19
|
1
|
50
|
|
|
|
7
|
croak "$class requires an even number of parameters" if @_ % 2; |
20
|
1
|
|
|
|
|
5
|
my %opts = @_; |
21
|
1
|
50
|
|
|
|
7
|
my %anyopts = ( $opts{json_any} ) ? %{$opts{json_any}} : (); |
|
0
|
|
|
|
|
0
|
|
22
|
1
|
|
33
|
|
|
12
|
bless( [ |
23
|
|
|
|
|
|
|
[], # BUFFER |
24
|
|
|
|
|
|
|
JSON::Any->new( %anyopts ), # OBJ |
25
|
|
|
|
|
|
|
\%opts, # PARAMS |
26
|
|
|
|
|
|
|
], ref $class || $class ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub get { |
30
|
1
|
|
|
1
|
1
|
441
|
my ($self, $lines) = @_; |
31
|
1
|
|
|
|
|
3
|
my $ret = []; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
2
|
foreach my $json (@$lines) { |
34
|
1
|
50
|
|
|
|
3
|
if ( my $obj = eval { $self->[ OBJ ]->jsonToObj( $json ) } ) { |
|
1
|
|
|
|
|
8
|
|
35
|
1
|
|
|
|
|
40
|
push( @$ret, $obj ); |
36
|
|
|
|
|
|
|
} else { |
37
|
0
|
|
|
|
|
0
|
warn "Couldn't convert json to an object: $@"; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
1
|
|
|
|
|
4
|
return $ret; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get_one_start { |
44
|
0
|
|
|
0
|
1
|
0
|
my ($self, $lines) = @_; |
45
|
0
|
0
|
|
|
|
0
|
$lines = [ $lines ] unless ( ref( $lines ) ); |
46
|
0
|
|
|
|
|
0
|
push( @{ $self->[ BUFFER ] }, @{ $lines } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_one { |
50
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
51
|
0
|
|
|
|
|
0
|
my $ret = []; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
0
|
if ( my $line = shift ( @{ $self->[ BUFFER ] } ) ) { |
|
0
|
|
|
|
|
0
|
|
54
|
0
|
0
|
|
|
|
0
|
if ( my $json = eval { $self->[ OBJ ]->jsonToObj( $line ) } ) { |
|
0
|
|
|
|
|
0
|
|
55
|
0
|
|
|
|
|
0
|
push( @$ret, $json ); |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
warn "Couldn't convert json to object: $@"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
return $ret; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub put { |
65
|
1
|
|
|
1
|
1
|
965
|
my ($self, $objects) = @_; |
66
|
1
|
|
|
|
|
3
|
my $ret = []; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
foreach my $obj (@$objects) { |
69
|
1
|
50
|
|
|
|
2
|
if ( my $json = eval { $self->[ OBJ ]->objToJson( $obj, $self->[ PARAMS ] ) } ) { |
|
1
|
|
|
|
|
12
|
|
70
|
1
|
|
|
|
|
61
|
push( @$ret, $json ); |
71
|
|
|
|
|
|
|
} else { |
72
|
0
|
|
|
|
|
0
|
warn "Couldn't convert object to json\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
4
|
return $ret; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |