| 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
| |||||||||||||
| 57 | |||||||||||||
| 58 | 2 | ▶ | $args{PeerService} //= 4730; | ||||||||||
|
Condition50%1/2
$args{"PeerService"} //= 4730
MC/DC0%0/1
$args{"PeerService"} //= 4730
$args{"PeerService"}
Truth table50%1/2
A
A= $args{"PeerService"}
| |||||||||||||
| 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"} ||= {}
MC/DC100%1/1
do {
*$self
}->{"gearman"} ||= {}
do {
*$self
}->{"gearman"}
Truth table100%2/2
A
A= do {
*$self
}->{"gearman"}
| |||||||||||||
| 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"} // ""
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"}
| |||||||||||||
| 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
| |||||||||||||
| 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; | |||||||||||