Sereal.pm

filter: Statementstmt 100% 15 / 15 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 21 / 21 CC 2 SCAR 3.4
CC
2
Cov
100%
__ANON__
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
↑ Summary Role/Sereal.pm »
1 package Mojo::IOLoop::Subprocess::Sereal;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '1.002';
8  
9 2 our @EXPORT = '$_subprocess';
10  
11 19 ▶our $_subprocess = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
12 19 my $subprocess = shift->subprocess
13 ->with_roles('Mojo::IOLoop::Subprocess::Role::Sereal')->with_sereal;
14 19 ▶ return @_ ? $subprocess->run(@_) : $subprocess;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 15 4 19
15 2 };
16  
17 2 1;
18  
19 =encoding utf8
20  
21 =head1 NAME
22  
23 Mojo::IOLoop::Subprocess::Sereal - Subprocesses with Sereal
24  
25 =head1 SYNOPSIS
26  
27 use Mojo::IOLoop::Subprocess::Sereal;
28  
29 # Operation that would block the event loop for 5 seconds
30 my $subprocess = Mojo::IOLoop->$_subprocess(
31 sub {
32 my $subprocess = shift;
33 sleep 5;
34 return '♥', 'Mojolicious';
35 },
36 sub {
37 my ($subprocess, $err, @results) = @_;
38 say "I $results[0] $results[1]!";
39 }
40 );
41  
42 # Start event loop if necessary
43 Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
44  
45 =head1 DESCRIPTION
46  
47 L<Mojo::IOLoop::Subprocess::Sereal> provides a L</"$_subprocess"> method which
48 works as a drop-in replacement for L<Mojo::IOLoop/"subprocess"> while using
49 L<Sereal> for data serialization. L<Sereal> is faster than L<Storable> and
50 supports serialization of more reference types such as C<Regexp>. The
51 L<Sereal::Encoder/"FREEZE/THAW CALLBACK MECHANISM"> is supported to control
52 serialization of blessed objects.
53  
54 See L<Mojo::IOLoop::Subprocess::Role::Sereal> for a role to apply L<Sereal>
55 data serialization to any L<Mojo::IOLoop::Subprocess>.
56  
57 =head1 EXPORTS
58  
59 L<Mojo::IOLoop::Subprocess::Sereal> exports the following variable by default.
60  
61 =head2 $_subprocess
62  
63 my $subprocess = Mojo::IOLoop->$_subprocess(sub {...}, sub {...});
64 my $subprocess = Mojo::IOLoop->$_subprocess;
65 my $subprocess = $loop->$_subprocess(sub {...}, sub {...});
66  
67 Build L<Mojo::IOLoop::Subprocess> object to perform computationally expensive
68 operations in subprocesses, without blocking the event loop. Composes and calls
69 L<Mojo::IOLoop::Subprocess::Role::Sereal/"with_sereal"> to use L<Sereal> for
70 data serialization. If arguments are provided, they will be used to call
71 L<Mojo::IOLoop::Subprocess/"run">.
72  
73 =head1 BUGS
74  
75 Report any issues on the public bugtracker.
76  
77 =head1 AUTHOR
78  
79 Dan Book <dbook@cpan.org>
80  
81 =head1 COPYRIGHT AND LICENSE
82  
83 This software is Copyright (c) 2016 by Dan Book.
84  
85 This is free software, licensed under:
86  
87 The Artistic License 2.0 (GPL Compatible)
88  
89 =head1 SEE ALSO
90  
91 L<Mojo::IOLoop>, L<Mojo::IOLoop::Subprocess::Role::Sereal>, L<Sereal>
↑ Summary Role/Sereal.pm »