line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Serialize; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
56714
|
use 5.010001; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
49
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
280
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
254
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
900
|
use AnyEvent::AggressiveIdle qw(aggressive_idle stop_aggressive_idle); |
|
1
|
|
|
|
|
17232
|
|
|
1
|
|
|
|
|
302
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
16
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
17
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# This allows declaration use AnyEvent::Serialize ':all'; |
20
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
21
|
|
|
|
|
|
|
# will save memory. |
22
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(serialize deserialize) ] ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our $block_size = 1024; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub import |
34
|
|
|
|
|
|
|
{ |
35
|
1
|
|
|
1
|
|
11
|
my ($class, @arg) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
5
|
for (reverse 0 .. $#arg - 1) { |
39
|
1
|
50
|
|
|
|
5
|
next unless $arg[$_] eq 'block_size'; |
40
|
1
|
|
|
|
|
11
|
my $bs = $arg[$_ + 1]; |
41
|
1
|
50
|
|
|
|
4
|
croak "Usage: use AnyEvent::Serialize block_size => 512 ..." |
42
|
|
|
|
|
|
|
unless $bs > 0; |
43
|
1
|
|
|
|
|
1
|
$block_size = $bs; |
44
|
1
|
|
|
|
|
4
|
splice @arg, $_, 2; |
45
|
1
|
|
|
|
|
3
|
last; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
161
|
return $class->export_to_level(1, $class, @arg); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub serialize($&) { |
53
|
0
|
|
|
0
|
1
|
0
|
require Data::StreamSerializer; |
54
|
1
|
|
|
1
|
|
10
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
55
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
297
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
*{ __PACKAGE__ . '::serialize' } = sub ($&) { |
58
|
0
|
|
|
0
|
|
0
|
my ($obj, $cb) = @_; |
59
|
0
|
|
|
|
|
0
|
my $sr = new Data::StreamSerializer $obj; |
60
|
0
|
|
|
|
|
0
|
$sr->block_size($block_size); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $str = $sr->next; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
if ($sr->is_eof()) { |
65
|
0
|
|
|
|
|
0
|
$cb->($str, $sr->recursion_detected); |
66
|
0
|
|
|
|
|
0
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
aggressive_idle { |
70
|
0
|
|
|
|
|
0
|
my $pid = shift; |
71
|
0
|
|
|
|
|
0
|
my $part = $sr->next; |
72
|
0
|
0
|
|
|
|
0
|
$str .= $part if defined $part; |
73
|
0
|
0
|
|
|
|
0
|
if ($sr->is_eof) { |
74
|
0
|
|
|
|
|
0
|
stop_aggressive_idle $pid; |
75
|
0
|
|
|
|
|
0
|
$cb->($str, $sr->recursion_detected); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
}; |
78
|
0
|
|
|
|
|
0
|
}; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
goto &serialize; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub deserialize($&) { |
84
|
1
|
|
|
1
|
1
|
4406182
|
require Data::StreamDeserializer; |
85
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
86
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
306
|
|
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
*{ __PACKAGE__ . '::deserialize' } = sub ($&) { |
89
|
0
|
|
|
0
|
|
|
my ($data, $cb) = @_; |
90
|
0
|
|
|
|
|
|
my $dsr = new Data::StreamDeserializer |
91
|
|
|
|
|
|
|
data => $data, block_size => $block_size; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if ($dsr->next_object) { |
94
|
0
|
|
|
|
|
|
$cb->($dsr->result, $dsr->error, $dsr->tail); |
95
|
0
|
|
|
|
|
|
return; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
aggressive_idle { |
99
|
0
|
|
|
|
|
|
my $pid = shift; |
100
|
0
|
0
|
|
|
|
|
return unless $dsr->next; |
101
|
0
|
|
|
|
|
|
stop_aggressive_idle($pid); |
102
|
0
|
|
|
|
|
|
$cb->($dsr->result('first'), $dsr->error, $dsr->tail); |
103
|
0
|
|
|
|
|
|
}; |
104
|
0
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
goto &deserialize; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |