Gearman/Task.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 55 CC 3 SCAR 12.8
CC
3
Cov
0%
BEGIN
6.0
pack_req
6.0
BUILDARGS
2.0
CRAP 3.6
1 package AnyEvent::Gearman::Task;
2 use Any::Moose;
3  
4 use AnyEvent::Gearman::Constants;
5  
6 BEGIN { do { eval q[use MouseX::Foreign; 1] or die $@ } if any_moose eq 'Mouse' }
7  
8 extends any_moose('::Object'), 'Object::Event';
9  
10 has function => (
11 is => 'rw',
12 isa => 'Str',
13 required => 1,
14 );
15  
16 has workload => (
17 is => 'rw',
18 isa => 'Str',
19 required => 1,
20 );
21  
22 has unique => (
23 is => 'rw',
24 isa => 'Str',
25 default => '',
26 );
27  
28 has job_handle => (
29 is => 'rw',
30 isa => 'Str',
31 default => '',
32 );
33  
34 has [qw/on_created on_data on_complete on_fail on_status on_warning/] => (
35 is => 'rw',
36 isa => 'CodeRef',
37 default => sub { sub {} },
38 );
39  
40 no Any::Moose;
41  
42 sub BUILDARGS {
43 my ($self, $function, $workload, %params) = @_;
44  
45 return {
46 function => $function,
47 workload => $workload,
48 %params,
49 }
50 }
51  
52 sub BUILD {
53 my $self = shift;
54  
55 $self->reg_cb(
56 on_created => $self->on_created,
57 on_data => $self->on_data,
58 on_complete => $self->on_complete,
59 on_fail => $self->on_fail,
60 on_status => $self->on_status,
61 on_warning => $self->on_warning,
62 );
63 }
64  
65 sub pack_req {
66 my ($self, $type) = @_;
67 $type = $type && $type eq 'bg'? SUBMIT_JOB_BG : SUBMIT_JOB;
68  
69 my $data = $self->function . "\0"
70 . $self->unique . "\0"
71 . $self->workload;
72  
73 "\0REQ" . pack('NN', $type, length($data)) . $data;
74 }
75  
76 sub pack_option_req {
77 my ($self, $option) = @_;
78  
79 "\0REQ" . pack('NN', OPTION_REQ, length($option)) . $option;
80 }
81  
82 __PACKAGE__->meta->make_immutable;
83  
84 __END__