line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::HiveJSO; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
1020
|
$AnyEvent::HiveJSO::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: HiveJSO stream serializer/deserializer for AnyEvent |
6
|
|
|
|
|
|
|
$AnyEvent::HiveJSO::VERSION = '0.002'; |
7
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1787
|
use AnyEvent::Handle; |
|
1
|
|
|
|
|
38127
|
|
|
1
|
|
|
|
|
43
|
|
11
|
1
|
|
|
1
|
|
1137
|
use HiveJSO; |
|
1
|
|
|
|
|
123394
|
|
|
1
|
|
|
|
|
79
|
|
12
|
1
|
|
|
1
|
|
13
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
410
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
AnyEvent::Handle::register_write_type(hivejso => sub { |
15
|
|
|
|
|
|
|
my ($self, @args) = @_; |
16
|
|
|
|
|
|
|
return HiveJSO->new({ @args })->hivejso if scalar @args > 1; |
17
|
|
|
|
|
|
|
my $data = $args[0]; |
18
|
|
|
|
|
|
|
my $ref = ref $data; |
19
|
|
|
|
|
|
|
if ($ref eq 'HASH') { |
20
|
|
|
|
|
|
|
return HiveJSO->new($data); |
21
|
|
|
|
|
|
|
} elsif ($ref eq 'ARRAY') { |
22
|
|
|
|
|
|
|
return HiveJSO->new({ @{$data} }); |
23
|
|
|
|
|
|
|
} elsif ($data->can('hivejso')) { |
24
|
|
|
|
|
|
|
return $data->hivejso; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
croak __PACKAGE__." can't handle this data with ref ".$ref; |
27
|
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
AnyEvent::Handle::register_read_type(hivejso => sub { |
30
|
|
|
|
|
|
|
my ( $self, $cb ) = @_; |
31
|
|
|
|
|
|
|
sub { |
32
|
|
|
|
|
|
|
my ( $obj, $post ) = HiveJSO->parse_seek($_[0]{rbuf}); |
33
|
|
|
|
|
|
|
if ($obj) { |
34
|
|
|
|
|
|
|
$_[0]{rbuf} = $post; |
35
|
|
|
|
|
|
|
$cb->( $_[0], $obj ); |
36
|
|
|
|
|
|
|
return 1; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return 0; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
__END__ |