Gearman/Worker.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« Gearman/Client.pm ↑ Summary Gearman.pm »
1 package AnyEvent::Gearman::Worker;
2 0 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=2.6
3  
4 use AnyEvent::Gearman::Types;
5 use AnyEvent::Gearman::Worker::Connection;
6  
7 BEGIN { do { eval q[use MouseX::Foreign; 1] or die $@ } if any_moose eq 'Mouse' }
8  
9 extends any_moose('::Object'), 'Object::Event';
10  
11 has job_servers => (
12 is => 'ro',
13 isa => 'AnyEvent::Gearman::Worker::Connections',
14 required => 1,
15 coerce => 1,
16 );
17  
18 has prefix => (
19 is => 'ro',
20 isa => 'Str',
21 default => '',
22 );
23  
24 has functions => (
25 is => 'ro',
26 isa => 'HashRef',
27 default => sub { {} },
28 );
29  
30 no Any::Moose;
31  
32 sub register_function {
33 my ($self, $func_name, $code) = @_;
34  
35 die qq[Function "$func_name" already registered]
36 if $self->functions->{ $func_name };
37  
38 for my $js (@{ $self->job_servers }) {
39 $js->context($self) unless $js->context;
40 $js->register_function( $func_name );
41 }
42  
43 $self->functions->{ $func_name } = $code;
44 }
45  
46 sub unregister_function {
47 my ($self, $func_name) = @_;
48  
49 for my $js (@{ $self->job_servers }) {
50 $js->context($self) unless $js->context;
51 $js->unregister_function( $func_name );
52 }
53  
54 delete $self->functions->{ $func_name };
55 }
56  
57 __PACKAGE__->meta->make_immutable;
58  
59 __END__
« Gearman/Client.pm ↑ Summary Gearman.pm »