Role/Sereal.pm

filter: Statementstmt 94.7% 18 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 92.3% 24 / 26 CC 1 SCAR 0.2
CC
1
Cov
95%
__ANON__
1.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Sereal.pm ↑ Summary
1 package Mojo::IOLoop::Subprocess::Role::Sereal;
2  
3 3 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Sereal::Decoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Sereal::Encoder;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '1.002';
8  
9 3 requires qw(deserialize serialize);
10  
11 3 my $deserializer = Sereal::Decoder->new;
12 19 ▶my $deserialize = sub { Sereal::Decoder::sereal_decode_with_object($deserializer, $_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 3 my $serializer = Sereal::Encoder->new({freeze_callbacks => 1});
15 0 ▶my $serialize = sub { Sereal::Encoder::sereal_encode_with_object($serializer, $_[0]) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
16  
17 20 ▶sub with_sereal { shift->deserialize($deserialize)->serialize($serialize) }
Subroutine with_sereal: called CC=1 SCAR=0.0
Pod documented
18  
19 3 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<Mojo::IOLoop::Subprocess::Role::Sereal> provides a L</"with_sereal"> method
50 for L<Mojo::IOLoop::Subprocess> objects that will update its C<serialize> and
51 C<deserialize> attributes to use L<Sereal> for data serialization. L<Sereal> is
52 faster than L<Storable> and supports serialization of more reference types such
53 as C<Regexp>. The L<Sereal::Encoder/"FREEZE/THAW CALLBACK MECHANISM"> is
54 supported to control serialization of blessed objects.
55  
56 See L<Mojo::IOLoop::Subprocess::Sereal> for a method to retrieve a subprocess
57 object using L<Sereal> directly from L<Mojo::IOLoop>.
58  
59 =head1 METHODS
60  
61 L<Mojo::IOLoop::Subprocess::Role::Sereal> composes the following methods.
62  
63 =head2 with_sereal
64  
65 $subprocess = $subprocess->with_sereal;
66  
67 Set L<Mojo::IOLoop::Subprocess/"deserialize"> and
68 L<Mojo::IOLoop::Subprocess/"serialize"> to callbacks that use L<Sereal> 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 <dbook@cpan.org>
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<Mojo::IOLoop::Subprocess>, L<Mojo::IOLoop::Subprocess::Sereal>, L<Sereal>
« Sereal.pm ↑ Summary