line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::IOLoop::Subprocess::Role::Sereal; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2469
|
use Role::Tiny; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
24
|
|
4
|
3
|
|
|
3
|
|
516
|
use Sereal::Decoder; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
113
|
|
5
|
3
|
|
|
3
|
|
19
|
use Sereal::Encoder; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
681
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.001'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw(deserialize serialize); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $deserializer = Sereal::Decoder->new; |
12
|
|
|
|
|
|
|
my $deserialize = sub { Sereal::Decoder::sereal_decode_with_object($deserializer, $_[0]) }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $serializer = Sereal::Encoder->new({freeze_callbacks => 1}); |
15
|
|
|
|
|
|
|
my $serialize = sub { Sereal::Encoder::sereal_encode_with_object($serializer, $_[0]) }; |
16
|
|
|
|
|
|
|
|
17
|
20
|
|
|
20
|
1
|
5926
|
sub with_sereal { shift->deserialize($deserialize)->serialize($serialize) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
1; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=encoding utf8 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 NAME |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Mojo::IOLoop::Subprocess::Role::Sereal - Subprocesses with Sereal |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Mojo::IOLoop; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Operation that would block the event loop for 5 seconds |
32
|
|
|
|
|
|
|
my $subprocess = Mojo::IOLoop->subprocess->with_roles('+Sereal')->with_sereal->run( |
33
|
|
|
|
|
|
|
sub { |
34
|
|
|
|
|
|
|
my $subprocess = shift; |
35
|
|
|
|
|
|
|
sleep 5; |
36
|
|
|
|
|
|
|
return '♥', 'Mojolicious'; |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
sub { |
39
|
|
|
|
|
|
|
my ($subprocess, $err, @results) = @_; |
40
|
|
|
|
|
|
|
say "I $results[0] $results[1]!"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Start event loop if necessary |
45
|
|
|
|
|
|
|
Mojo::IOLoop->start unless Mojo::IOLoop->is_running; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
L provides a L"with_sereal"> method |
50
|
|
|
|
|
|
|
for L objects that will update its C and |
51
|
|
|
|
|
|
|
C attributes to use L for data serialization. L is |
52
|
|
|
|
|
|
|
faster than L and supports serialization of more reference types such |
53
|
|
|
|
|
|
|
as C. The L is |
54
|
|
|
|
|
|
|
supported to control serialization of blessed objects. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
See L for a method to retrieve a subprocess |
57
|
|
|
|
|
|
|
object using L directly from L. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L composes the following methods. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 with_sereal |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$subprocess = $subprocess->with_sereal; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Set L and |
68
|
|
|
|
|
|
|
L to callbacks that use L for |
69
|
|
|
|
|
|
|
data serialization. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 BUGS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Report any issues on the public bugtracker. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Dan Book |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Dan Book. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is free software, licensed under: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SEE ALSO |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L, L, L |