Net/Gearman.pm

filter: Statementstmt 100% 33 / 33 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 12 / 12 Podpod 25.0% 1 / 4 totaltotal 87.1% 54 / 62 CC 6 SCAR 5.6
CC
6
Cov
93%
new
3.2
do_read
2.0
gearman_state
2.0
CRAP 1.7
« Protocol/Gearman.pm ↑ Summary Protocol/Gearman/Worker.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2014,2026 -- leonerd@leonerd.org.uk
5  
6 package Net::Gearman 0.05;
7  
8 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use feature qw( postderef signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶no warnings qw( experimental::postderef experimental::signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use base qw( IO::Socket::IP );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 C<Net::Gearman> - provide a synchronous concrete Gearman implementation
19  
20 =head1 DESCRIPTION
21  
22 =for highlighter language=perl
23  
24 This module provides a simple synchronous concrete implementation to run a
25 L<Protocol::Gearman::Client> or L<Protocol::Gearman::Worker> on top of. It
26 shouldn't be used directly; see instead
27  
28 =over 2
29  
30 =item *
31  
32 L<Net::Gearman::Client>
33  
34 =item *
35  
36 L<Net::Gearman::Worker>
37  
38 =back
39  
40 =head1 CONSTRUCTOR
41  
42 =cut
43  
44 =head2 new
45  
46 $gearman = Net::Gearman->new( %args );
47  
48 Returns a new C<Net::Gearman> object. Takes the same arguments as
49 C<IO::Socket::IP>. Sets a default value for C<PeerService> if not provided of
50 4730.
51  
52 =cut
53  
54 2 ▶sub new ( $class, @args )
Subroutine new: called CC=3 SCAR=11.7
Pod documented
55 {
56 2 ▶ my %args = @args == 1 ? ( PeerHost => shift @args ) : @args;
Branch: 1 branch
BranchTrueFalseTotal
@args == 1 ? : 0 2 2
57  
58 2 ▶ $args{PeerService} //= 4730;
Condition50%1/2
$args{"PeerService"} //= 4730
l!l
20
MC/DC0%0/1
$args{"PeerService"} //= 4730
$args{"PeerService"}
Truth table50%1/2
A
A= $args{"PeerService"}
Aresult
11
00
59  
60 2 return $class->SUPER::new( %args );
61 }
62  
63 9 ▶sub gearman_state ( $self )
Subroutine gearman_state: called CC=2 SCAR=6.9
Pod undocumented
64 {
65 9 ▶ ${*$self}{gearman} ||= {};
Condition100%2/2
do { *$self }->{"gearman"} ||= {}
l!l
72
MC/DC100%1/1
do { *$self }->{"gearman"} ||= {}
do { *$self }->{"gearman"}
Truth table100%2/2
A
A= do { *$self }->{"gearman"}
Aresult
11
00
66 }
67  
68 3 ▶sub new_future ( $self )
Subroutine new_future: called CC=1 SCAR=0.0
Pod undocumented
69 {
70 3 return Net::Gearman::Future->new( $self );
71 }
72  
73 2 ▶sub do_read ( $self )
Subroutine do_read: called CC=2 SCAR=7.0
Pod undocumented
74 {
75 2 ▶ my $buffer = $self->gearman_state->{gearman_buffer} // "";
Condition50%1/2
$self->gearman_state->{"gearman_buffer"} // ""
l!l
02
MC/DC0%0/1
$self->gearman_state->{"gearman_buffer"} // ""
$self->gearman_state->{"gearman_buffer"}
Truth table50%1/2
A
A= $self->gearman_state->{"gearman_buffer"}
Aresult
11
00
76  
77 # TODO: consider an on_recv_packet to make this more efficient
78 2 $self->sysread( $buffer, 8192, length $buffer );
79 2 $self->on_recv( $buffer );
80  
81 2 $self->gearman_state->{gearman_buffer} = $buffer;
82 }
83  
84 package # hide
85 Net::Gearman::Future;
86 3 ▶use base qw( Future );
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 3 ▶sub new ( $class, $gearman )
Subroutine new: called CC=1 SCAR=0.0
89 {
90 3 my $self = $class->SUPER::new;
91 3 $self->set_udata( gearman => $gearman );
92 3 return $self;
93 }
94  
95 2 ▶sub await ( $self )
Subroutine await: called CC=2 SCAR=6.9
96 {
97 2 ▶ while( !$self->is_ready ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->is_ready) 2 2 4
98 2 $self->udata( 'gearman' )->do_read;
99 }
100 }
101  
102 =head1 AUTHOR
103  
104 Paul Evans <leonerd@leonerd.org.uk>
105  
106 =cut
107  
108 3 0x55AA;
« Protocol/Gearman.pm ↑ Summary Protocol/Gearman/Worker.pm »