Server/Job.pm

filter: Statementstmt 27.3% 23 / 84 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 33.3% 7 / 21 Podpod 0.0% 0 / 14 totaltotal 19.8% 30 / 151 CC 16 SCAR 25.2
CC
16
Cov
21%
new
30.0
relay_to_option_listeners
30.0
relay_to_listeners
20.0
CRAP 12.5
« Server/Listener.pm ↑ Summary
1 package Gearman::Server::Job;
2 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Gearman::Server::Job::VERSION = qv("v1.130.1");
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Gearman::Server::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 'func',
14 'uniq',
15 'argref',
16 'listeners', # arrayref of interested Clients
17 'worker',
18 'handle',
19 'status', # [1, 100]
20 'require_listener',
21 'server', # Gearman::Server that owns us
22 1 );
23  
24 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
25 0 my Gearman::Server::Job $self = shift;
26 0 my ($server, $func, $uniq, $argref, $highpri) = @_;
27  
28 0 ▶ $self = fields::new($self) unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
29  
30 # if they specified a uniq, see if we have a dup job running already
31 # to merge with
32 0 ▶ if (length($uniq)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $uniq) 0 0 0
33 # a unique value of "-" means "use my args as my unique key"
34 0 ▶ $uniq = $$argref if $uniq eq "-";
Branch: 1 branch
BranchTrueFalseTotal
if $uniq eq "-" 0 0 0
35 0 ▶ if (my $job = $server->job_of_unique($func, $uniq)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $job = $server->job_of_unique($func, $uniq)) 0 0 0
36 # found a match
37 0 return $job;
38 }
39 # create a new key
40 0 $server->set_unique_job($func, $uniq => $self);
41 }
42  
43 0 $self->{'server'} = $server;
44 0 $self->{'func'} = $func;
45 0 $self->{'uniq'} = $uniq;
46 0 $self->{'argref'} = $argref;
47 0 $self->{'require_listener'} = 1;
48 0 $self->{'listeners'} = [];
49 0 $self->{'handle'} = $server->new_job_handle;
50  
51 0 $server->enqueue_job($self, $highpri);
52 0 return $self;
53 }
54  
55 0 ▶sub add_listener {
Subroutine add_listener: not called CC=1 SCAR=6.9
Pod undocumented
56 0 my Gearman::Server::Job $self = shift;
57 0 my Gearman::Server::Client $li = shift;
58  
59 0 push @{$self->{listeners}}, $li;
60 0 Scalar::Util::weaken($self->{listeners}->[-1]);
61 }
62  
63 0 ▶sub relay_to_listeners {
Subroutine relay_to_listeners: not called CC=4 SCAR=30.0
Pod undocumented
64 0 my Gearman::Server::Job $self = shift;
65 0 foreach my Gearman::Server::Client $c (@{$self->{listeners}}) {
66 0 ▶ next if !$c || $c->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if not $c or $c->{"closed"} 0 0 0
Condition0%0/3
not $c or $c->{"closed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $c or $c->{"closed"}
not $c $c->{"closed"}
Truth table0%0/3
not(A) or B
A= not $cB= $c->{"closed"}
ABresult
1X1
011
000
67 0 $c->write($_[0]);
68 }
69 }
70  
71 0 ▶sub relay_to_option_listeners {
Subroutine relay_to_option_listeners: not called CC=5 SCAR=34.0
Pod undocumented
72 0 my Gearman::Server::Job $self = shift;
73 0 my $option = $_[1];
74 0 foreach my Gearman::Server::Client $c (@{$self->{listeners}}) {
75 0 ▶ next if !$c || $c->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if not $c or $c->{"closed"} 0 0 0
Condition0%0/3
not $c or $c->{"closed"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not $c or $c->{"closed"}
not $c $c->{"closed"}
Truth table0%0/3
not(A) or B
A= not $cB= $c->{"closed"}
ABresult
1X1
011
000
76 0 ▶ next unless $c->option($option);
Branch: 1 branch
BranchTrueFalseTotal
unless $c->option($option) 0 0 0
77 0 $c->write($_[0]);
78 }
79  
80 }
81  
82 0 ▶sub clear_listeners {
Subroutine clear_listeners: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my Gearman::Server::Job $self = shift;
84 0 $self->{listeners} = [];
85 }
86  
87 0 ▶sub listeners {
Subroutine listeners: not called CC=1 SCAR=6.9
Pod undocumented
88 0 my Gearman::Server::Job $self = shift;
89 0 return @{$self->{listeners}};
90 }
91  
92 0 ▶sub uniq {
Subroutine uniq: not called CC=1 SCAR=6.9
Pod undocumented
93 0 my Gearman::Server::Job $self = shift;
94 0 return $self->{uniq};
95 }
96  
97 0 ▶sub note_finished {
Subroutine note_finished: not called CC=2 SCAR=17.9
Pod undocumented
98 0 my Gearman::Server::Job $self = shift;
99 0 my $success = shift;
100  
101 0 $self->{server}->note_job_finished($self);
102  
103 0 ▶ if ($Gearmand::graceful_shutdown) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Gearmand::graceful_shutdown) 0 0 0
104 0 Gearmand::shutdown_if_calm();
105 }
106 }
107  
108 # accessors:
109 0 ▶sub worker {
Subroutine worker: not called CC=2 SCAR=17.9
Pod undocumented
110 0 my Gearman::Server::Job $self = shift;
111 0 ▶ return $self->{'worker'} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
112 0 return $self->{'worker'} = shift;
113 }
114 0 ▶sub require_listener {
Subroutine require_listener: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my Gearman::Server::Job $self = shift;
116 0 ▶ return $self->{'require_listener'} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
117 0 return $self->{'require_listener'} = shift;
118 }
119  
120 # takes arrayref of [numerator,denominator]
121 0 ▶sub status {
Subroutine status: not called CC=2 SCAR=17.9
Pod undocumented
122 0 my Gearman::Server::Job $self = shift;
123 0 ▶ return $self->{'status'} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
124 0 return $self->{'status'} = shift;
125 }
126  
127 0 ▶sub handle {
Subroutine handle: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my Gearman::Server::Job $self = shift;
129 0 return $self->{'handle'};
130 }
131  
132 0 ▶sub func {
Subroutine func: not called CC=1 SCAR=6.9
Pod undocumented
133 0 my Gearman::Server::Job $self = shift;
134 0 return $self->{'func'};
135 }
136  
137 0 ▶sub argref {
Subroutine argref: not called CC=1 SCAR=6.9
Pod undocumented
138 0 my Gearman::Server::Job $self = shift;
139 0 return $self->{'argref'};
140 }
141  
142 1 1;
« Server/Listener.pm ↑ Summary