| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package AnyEvent::Gearman::Task; | 
| 2 | 6 |  |  | 6 |  | 39 | use Any::Moose; | 
|  | 6 |  |  |  |  | 14 |  | 
|  | 6 |  |  |  |  | 47 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 6 |  |  | 6 |  | 9831 | use AnyEvent::Gearman::Constants; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 2167 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 6 | 50 |  | 6 |  | 27 | BEGIN { do { eval q[use MouseX::Foreign; 1] or die $@ } if any_moose eq 'Mouse' } | 
|  | 6 | 50 |  | 6 |  | 1144 |  | 
|  | 6 |  |  |  |  | 6196 |  | 
|  | 6 |  |  |  |  | 26854 |  | 
|  | 6 |  |  |  |  | 45 |  | 
| 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 | 6 |  |  | 6 |  | 62 | no Any::Moose; | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 76 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub BUILDARGS { | 
| 43 | 15 |  |  | 15 | 1 | 368 | my ($self, $function, $workload, %params) = @_; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | return { | 
| 46 | 15 |  |  |  |  | 264 | function => $function, | 
| 47 |  |  |  |  |  |  | workload => $workload, | 
| 48 |  |  |  |  |  |  | %params, | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub BUILD { | 
| 53 | 15 |  |  | 15 | 1 | 251 | my $self = shift; | 
| 54 |  |  |  |  |  |  |  | 
| 55 | 15 |  |  |  |  | 297 | $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 | 11 |  |  | 11 | 1 | 26 | my ($self, $type) = @_; | 
| 67 | 11 | 100 | 66 |  |  | 491 | $type = $type && $type eq 'bg'? SUBMIT_JOB_BG : SUBMIT_JOB; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 11 |  |  |  |  | 198 | my $data = $self->function . "\0" | 
| 70 |  |  |  |  |  |  | . $self->unique . "\0" | 
| 71 |  |  |  |  |  |  | . $self->workload; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 11 |  |  |  |  | 160 | "\0REQ" . pack('NN', $type, length($data)) . $data; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub pack_option_req { | 
| 77 | 0 |  |  | 0 | 1 |  | my ($self, $option) = @_; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 0 |  |  |  |  |  | "\0REQ" . pack('NN', OPTION_REQ, length($option)) . $option; | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | __END__ |