| 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::Worker 0.05; | ||
| 7 | |||
| 8 | 2 | ▶ | use v5.20; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 2 | ▶ | use feature qw( postderef signatures ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 2 | ▶ | no warnings qw( experimental::postderef experimental::signatures ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | 2 | ▶ | use base qw( Net::Gearman Protocol::Gearman::Worker ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | |||
| 16 | =head1 NAME | ||
| 17 | |||
| 18 | C<Net::Gearman::Worker> - concrete Gearman worker over an IP socket | ||
| 19 | |||
| 20 | =head1 SYNOPSIS | ||
| 21 | |||
| 22 | =for highlighter language=perl | ||
| 23 | |||
| 24 | use List::Util qw( sum ); | ||
| 25 | use Net::Gearman::Worker; | ||
| 26 | |||
| 27 | my $worker = Net::Gearman::Worker->new( | ||
| 28 | PeerAddr => $SERVER, | ||
| 29 | ) or die "Cannot connect - $@\n"; | ||
| 30 | |||
| 31 | $worker->can_do( 'sum' ); | ||
| 32 | |||
| 33 | while(1) { | ||
| 34 | my $job = $worker->grab_job->get; | ||
| 35 | |||
| 36 | my $total = sum split m/,/, $job->arg; | ||
| 37 | |||
| 38 | $job->complete( $total ); | ||
| 39 | } | ||
| 40 | |||
| 41 | =head1 DESCRIPTION | ||
| 42 | |||
| 43 | This module combines the abstract L<Protocol::Gearman::Worker> with | ||
| 44 | L<Net::Gearman> to provide a simple synchronous concrete worker | ||
| 45 | implementation. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | =head1 AUTHOR | ||
| 50 | |||
| 51 | Paul Evans <leonerd@leonerd.org.uk> | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | 2 | 0x55AA; | |