File Coverage

blib/lib/Net/Gearman.pm
Criterion Covered Total %
statement 52 52 100.0
branch 1 2 50.0
condition 4 6 66.6
subroutine 12 12 100.0
pod 1 4 25.0
total 70 76 92.1


line stmt bran cond sub pod time code
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     3   402 use v5.20;
  3         7  
9 3     3   10 use warnings;
  3         5  
  3         115  
10              
11 3     3   13 use feature qw( postderef signatures );
  3         4  
  3         352  
12 3     3   15 no warnings qw( experimental::postderef experimental::signatures );
  3         5  
  3         116  
13              
14 3     3   10 use base qw( IO::Socket::IP );
  3         3  
  3         1220  
15              
16             =head1 NAME
17              
18             C - 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 or L on top of. It
26             shouldn't be used directly; see instead
27              
28             =over 2
29              
30             =item *
31              
32             L
33              
34             =item *
35              
36             L
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 object. Takes the same arguments as
49             C. Sets a default value for C if not provided of
50             4730.
51              
52             =cut
53              
54 2         4 sub new ( $class, @args )
55 2     2 1 310112 {
  2         6  
  2         10  
56 2 50       13 my %args = @args == 1 ? ( PeerHost => shift @args ) : @args;
57              
58 2   50     9 $args{PeerService} //= 4730;
59              
60 2         12 return $class->SUPER::new( %args );
61             }
62              
63             sub gearman_state ( $self )
64 9     9 0 10 {
  9         9  
  9         10  
65 9   100     10 ${*$self}{gearman} ||= {};
  9         52  
66             }
67              
68             sub new_future ( $self )
69 3     3 0 4 {
  3         5  
  3         3  
70 3         12 return Net::Gearman::Future->new( $self );
71             }
72              
73             sub do_read ( $self )
74 2     2 0 30 {
  2         2  
  2         3  
75 2   50     5 my $buffer = $self->gearman_state->{gearman_buffer} // "";
76              
77             # TODO: consider an on_recv_packet to make this more efficient
78 2         56 $self->sysread( $buffer, 8192, length $buffer );
79 2         66 $self->on_recv( $buffer );
80              
81 2         5 $self->gearman_state->{gearman_buffer} = $buffer;
82             }
83              
84             package # hide
85             Net::Gearman::Future;
86 3     3   31744 use base qw( Future );
  3         11  
  3         1875  
87              
88 3         5 sub new ( $class, $gearman )
89 3     3   4 {
  3         3  
  3         4  
90 3         21 my $self = $class->SUPER::new;
91 3         30 $self->set_udata( gearman => $gearman );
92 3         31 return $self;
93             }
94              
95             sub await ( $self )
96 2     2   1069 {
  2         3  
  2         3  
97 2         10 while( !$self->is_ready ) {
98 2         79 $self->udata( 'gearman' )->do_read;
99             }
100             }
101              
102             =head1 AUTHOR
103              
104             Paul Evans
105              
106             =cut
107              
108             0x55AA;