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