Task.pm

filter: Statementstmt 97.3% 148 / 152 Branchbran 72.9% 54 / 74 Conditioncond 80.7% 21 / 26 MC/DCmcdc 60.0% 9 / 15 Subroutinesub 93.3% 28 / 30 Podpod 5.0% 1 / 20 totaltotal 82.3% 261 / 317 CC 51 SCAR 14.0
CC
51
Cov
88%
new
9.1
final_fail
5.2
pack_submit_packet
5.0
CRAP 4.1
« Objects.pm ↑ Summary JobStatus.pm »
1 package Gearman::Task;
2 7 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 $Gearman::Task::VERSION = version->declare("2.004.015");
4  
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Gearman::Task - a task in Gearman, from the point of view of a client
11  
12 =head1 SYNOPSIS
13  
14 my $task = Gearman::Task->new("add", "1+2", {
15 ...
16 });
17  
18 $taskset->add_task($task);
19 $client->do_task($task);
20 $client->dispatch_background($task);
21  
22  
23 =head1 DESCRIPTION
24  
25 I<Gearman::Task> is a Gearman::Client's representation of a task to be
26 done.
27  
28 =head1 USAGE
29  
30 =head2 Gearman::Task->new($func, $arg, \%options)
31  
32 Creates a new I<Gearman::Task> object, and returns the object.
33  
34 I<$func> is the function name to be run. (that you have a worker registered to process)
35  
36 I<$arg> is an opaque scalar or scalarref representing the argument(s)
37 to pass to the distributed function. If you want to pass multiple
38 arguments, you must encode them somehow into this one. That's up to
39 you and your worker.
40  
41 I<%options> can contain:
42  
43 =over 4
44  
45 =item
46  
47 uniq
48  
49 A key which indicates to the server that other tasks with the same
50 function name and key will be merged into one. That is, the task
51 will be run just once, but all the listeners waiting on that job
52 will get the response multiplexed back to them.
53  
54 Uniq may also contain the magic value "-" (a single hyphen) which
55 means the uniq key is the contents of the args.
56  
57 =item
58  
59 on_complete
60  
61 A subroutine reference to be invoked when the task is completed. The
62 subroutine will be passed a reference to the return value from the worker
63 process.
64  
65 =item
66  
67 on_fail
68  
69 A subroutine reference to be invoked when the task fails (or fails for
70 the last time, if retries were specified). The reason could be passed
71 to this callback as an argument. This callback won't be called after a
72 failure if more retries are still possible.
73  
74 =item
75  
76 on_retry
77  
78 A subroutine reference to be invoked when the task fails, but is about
79 to be retried.
80  
81 Is passed one argument, what retry attempt number this is. (starts with 1)
82  
83 =item
84  
85 on_status
86  
87 A subroutine reference to be invoked if the task emits status updates.
88 Arguments passed to the subref are ($numerator, $denominator), where those
89 are left up to the client and job to determine.
90  
91 =item
92  
93 on_warning
94  
95 A subroutine reference to be invoked if the task emits status updates.
96 Arguments passed to the subref are ($numerator, $denominator), where those
97 are left up to the client and job to determine.
98  
99 =item
100  
101 retry_count
102  
103 Number of times job will be retried if there are failures. Defaults to 0.
104  
105 =item
106  
107 high_priority
108  
109 B<the option high_priority is deprecated>. Use C<< priority => high >> instead.
110 Boolean, whether this job should take priority over other jobs already
111 enqueued.
112  
113 =item
114  
115 priority
116  
117 valid value:
118  
119 =over
120  
121 =item
122  
123 high
124  
125 =item
126  
127 normal (defaul)
128  
129 =item
130  
131 low
132  
133 =back
134  
135 =item
136  
137 timeout
138  
139 Automatically fail, calling your on_fail callback, after this many
140 seconds have elapsed without an on_fail or on_complete being
141 called. Defaults to 0, which means never. Bypasses any retry_count
142 remaining.
143  
144 =item
145  
146 try_timeout
147  
148 Automatically fail, calling your on_retry callback (or on_fail if out of
149 retries), after this many seconds have elapsed. Defaults to 0, which means
150 never.
151  
152 =back
153  
154 =cut
155  
156 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
157 7 ▶use Gearman::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
158 7 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
159 7 ▶use String::CRC32 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
160 7 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 7 ▶use fields (
Subroutine BEGIN: called CC=1 SCAR=0.0
163  
164 # from client:
165 7 'func',
166 'argref',
167  
168 # opts from client:
169 'uniq',
170 'on_complete',
171 'on_data',
172 'on_fail',
173 'on_exception',
174 'on_warning',
175 'on_retry',
176 'on_status',
177 'on_post_hooks',
178  
179 # used internally,
180 # when other hooks are done running,
181 # prior to cleanup
182 'retry_count',
183 'timeout',
184 'try_timeout',
185 'high_priority',
186 'background',
187  
188 # from server:
189 'handle',
190  
191 # maintained by this module:
192 'retries_done',
193 'is_finished',
194 'taskset',
195  
196 # jobserver socket.
197 # shared by other tasks in the same taskset,
198 # but not w/ tasks in other tasksets using
199 # the same Gearman::Client
200 'jssock',
201  
202 # hookname -> coderef
203 'hooks',
204 'priority',
205 7 );
206  
207 # constructor, given: ($func, $argref, $opts);
208 20 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
209 20 my $self = shift;
210 20 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 20 0 20
211 20 $self = fields::new($self);
212 }
213  
214 $self->{func} = shift
215 20 ▶ or Carp::croak("No function given");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"func"} = shift() or Carp::croak("No function given") 19 1 20
216  
217 19 ▶ $self->{argref} = shift || do { my $empty = ""; \$empty; };
Condition66%2/3
shift() || do { my $empty = ''; \$empty }
l!l&&r!l&&!r
9100
MC/DC0%0/2
shift() || do { my $empty = ''; \$empty }
shift() do { my $empty = ''; \$empty }
Truth table66%2/3
A || B
A= shift()B= do { my $empty = ''; \$empty }
ABresult
1X1
011
000
218 19 ▶ (ref $self->{argref} eq "SCALAR")
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"argref"} eq "SCALAR" or Carp::croak("Argref not a scalar reference") 19 0 19
219 || Carp::croak("Argref not a scalar reference");
220  
221 19 ▶ my $opts = shift || {};
Condition100%2/2
shift() || {}
l!l
172
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
222  
223 19 $self->{$_} = delete $opts->{$_} for qw/
224 background
225 high_priority
226 on_complete
227 on_data
228 on_exception
229 on_fail
230 on_retry
231 on_status
232 on_warning
233 retry_count
234 timeout
235 try_timeout
236 uniq
237 /;
238  
239 19 $self->_priority(delete $opts->{priority});
240  
241 19 ▶ $self->{retry_count} ||= 0;
Condition100%2/2
$self->{"retry_count"} ||= 0
l!l
118
MC/DC100%1/1
$self->{"retry_count"} ||= 0
$self->{"retry_count"}
Truth table100%2/2
A
A= $self->{"retry_count"}
Aresult
11
00
242  
243 # bool: if success or fail has been called yet on this.
244 19 $self->{is_finished} = 0;
245  
246 19 ▶ if (%{$opts}) {
Branch: 1 branch
BranchTrueFalseTotal
if (%{$opts;}) 1 18 19
247 1 Carp::croak("Unknown option(s): " . join(", ", sort keys %$opts));
248 }
249  
250 18 $self->{retries_done} = 0;
251  
252 18 return $self;
253 } ## end sub new
254  
255 #=head1 METHODS
256 #
257 #=head2 run_hook($name)
258 #
259 #run a hook callback if defined
260 #
261 #=cut
262  
263 9 ▶sub run_hook {
Subroutine run_hook: called CC=4 SCAR=14.0
Pod undocumented
264 9 my ($self, $name) = (shift, shift);
265 9 ▶ ($name && $self->{hooks}->{$name}) || return;
Branch: 1 branch
BranchTrueFalseTotal
$name and $self->{"hooks"}{$name} or return 1 8 9
Condition66%2/3
$name and $self->{"hooks"}{$name}
!ll&&!rl&&r
081
MC/DC50%1/2
$name and $self->{"hooks"}{$name}
$name $self->{"hooks"}{$name}
Truth table66%2/3
A and B
A= $nameB= $self->{"hooks"}{$name}
ABresult
0X0
100
111
266  
267 1 eval { $self->{hooks}->{$name}->(@_) };
268 1 ▶ warn "Gearman::Task hook '$name' threw error: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
269 } ## end sub run_hook
270  
271 #=head2 add_hook($name, $cb)
272 #
273 #add a hook
274 #
275 #=cut
276  
277 2 ▶sub add_hook {
Subroutine add_hook: called CC=3 SCAR=11.0
Pod undocumented
278 2 my ($self, $name) = (shift, shift);
279 2 ▶ $name || return;
Branch: 1 branch
BranchTrueFalseTotal
$name or return 2 0 2
280  
281 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 1 2
282 1 $self->{hooks}->{$name} = shift;
283 }
284 else {
285 1 delete $self->{hooks}->{$name};
286 }
287 } ## end sub add_hook
288  
289 #=head2 is_finished()
290 #
291 #B<return> bool: whether or not task is totally done (on_failure or
292 #on_complete callback has been called)
293 #
294 #=cut
295  
296 0 ▶sub is_finished {
Subroutine is_finished: not called CC=1 SCAR=6.9
Pod undocumented
297 0 return shift->{is_finished};
298 }
299  
300 #=head2 taskset()
301 #
302 #getter
303 #
304 #=head2 taskset($ts)
305 #
306 #setter
307 #
308 #B<return> Gearman::Taskset
309 #
310 #=cut
311  
312 8 ▶sub taskset {
Subroutine taskset: called CC=5 SCAR=16.1
Pod undocumented
313 8 my $self = shift;
314  
315 # getter
316 8 ▶ return $self->{taskset} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 3 5 8
317  
318 # setter
319 5 my $ts = shift;
320 5 ▶ (Scalar::Util::blessed($ts) && $ts->isa("Gearman::Taskset"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($ts) and $ts->isa("Gearman::Taskset") or Carp::croak("argument is not an instance of Gearman::Taskset") 4 1 5
Condition66%2/3
builtin::blessed($ts) and $ts->isa("Gearman::Taskset")
!ll&&!rl&&r
104
MC/DC50%1/2
builtin::blessed($ts) and $ts->isa("Gearman::Taskset")
builtin::blessed($ts) $ts->isa("Gearman::Taskset")
Truth table66%2/3
A and B
A= builtin::blessed($ts)B= $ts->isa("Gearman::Taskset")
ABresult
0X0
100
111
321 || Carp::croak("argument is not an instance of Gearman::Taskset");
322 4 $self->{taskset} = $ts;
323  
324 4 ▶ if (my $hash_num = $self->hash()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hash_num = $self->hash) { } 2 2 4
325 2 $self->{jssock} = $ts->_get_hashed_sock($hash_num);
326 }
327 else {
328 2 $self->{jssock} = $ts->_get_default_sock;
329 }
330  
331 4 return $self->{taskset};
332 } ## end sub taskset
333  
334 #=head2 hash()
335 #
336 #B<return> undef on non-uniq packet, or the hash value (0-32767) if uniq
337 #
338 #=cut
339  
340 8 ▶sub hash {
Subroutine hash: called CC=4 SCAR=13.9
Pod undocumented
341 8 my $self = shift;
342 my $merge_on = $self->{uniq}
343 8 ▶ && $self->{uniq} eq "-" ? $self->{argref} : \$self->{uniq};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'uniq'} && $self->{'uniq'} eq '-' ? : 3 5 8
Condition100%3/3
$self->{"uniq"} and $self->{"uniq"} eq "-"
!ll&&!rl&&r
233
MC/DC100%2/2
$self->{"uniq"} and $self->{"uniq"} eq "-"
$self->{"uniq"} $self->{"uniq"} eq "-"
Truth table100%3/3
A and B
A= $self->{"uniq"}B= $self->{"uniq"} eq "-"
ABresult
0X0
100
111
344 8 ▶ if (${$merge_on}) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$merge_on;}) { } 6 2 8
345 6 return (String::CRC32::crc32(${$merge_on}) >> 16) & 0x7fff;
346 }
347 else {
348 2 return;
349 }
350 } ## end sub hash
351  
352 #=head2 pack_submit_packet([$client])
353 #
354 #B<return> Gearman::Util::pack_req_command(mode, func, uniq, argref)
355 #
356 #=cut
357  
358 4 ▶sub pack_submit_packet {
Subroutine pack_submit_packet: called CC=5 SCAR=16.1
Pod undocumented
359 4 my ($self, $client) = @_;
360  
361 # $client should be optional for sake of Gearman::Client::Async
362 # see https://github.com/p-alik/perl-Gearman/issues/10
363 4 ▶ my $func = $client ? $client->func($self->func) : $self->func;
Branch: 1 branch
BranchTrueFalseTotal
$client ? : 2 2 4
364  
365 return Gearman::Util::pack_req_command(
366 $self->mode,
367 join(
368 4 ▶ "\0", $func || '', $self->{uniq} || '', ${ $self->{argref} } || ''
Condition83%5/6
$func || ''
l!l
40
$self->{'uniq'} || ''
l!l
22
${$self->{'argref'};} || ''
l!l
22
MC/DC0%0/1
$func || ''
$func
MC/DC100%1/1
$self->{'uniq'} || ''
$self->{'uniq'}
MC/DC100%1/1
${$self->{'argref'};} || ''
${$self->{'argref'};}
Truth table50%1/2
A
A= $func
Aresult
11
00
Truth table100%2/2
A
A= $self->{'uniq'}
Aresult
11
00
Truth table100%2/2
A
A= ${$self->{'argref'};}
Aresult
11
00
369 )
370 );
371 } ## end sub pack_submit_packet
372  
373 #=head2 fail($reason)
374 #
375 #=cut
376  
377 7 ▶sub fail {
Subroutine fail: called CC=4 SCAR=13.9
Pod undocumented
378 7 my ($self, $reason) = @_;
379 7 ▶ return if $self->{is_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_finished"} 1 6 7
380  
381 # try to retry, if we can
382 6 ▶ if ($self->{retries_done} < $self->{retry_count}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"retries_done"} < $self->{"retry_count"}) 1 5 6
383 1 $self->{retries_done}++;
384 1 ▶ $self->{on_retry}->($self->{retries_done}) if $self->{on_retry};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_retry"} 1 0 1
385 1 $self->handle(undef);
386 1 return $self->{taskset}->add_task($self);
387 } ## end if ($self->{retries_done...})
388  
389 5 $self->final_fail($reason);
390 } ## end sub fail
391  
392 #=head2 final_fail($reason)
393 #
394 #if C<< !is_finished >> runs the hooks
395 #
396 #=over
397 #
398 #=item
399 #
400 #on_fail
401 #
402 #=item
403 #
404 #on_post_hooks
405 #
406 #=back
407 #
408 #=cut
409  
410 6 ▶sub final_fail {
Subroutine final_fail: called CC=5 SCAR=16.4
Pod undocumented
411 6 my ($self, $reason) = @_;
412  
413 6 ▶ return if $self->{is_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_finished"} 0 6 6
414 6 ▶ $self->{is_finished} = $reason || 1;
Condition50%1/2
$reason || 1
l!l
60
MC/DC0%0/1
$reason || 1
$reason
Truth table50%1/2
A
A= $reason
Aresult
11
00
415  
416 6 $self->run_hook('final_fail', $self);
417  
418 6 ▶ $self->{on_fail}->($reason) if $self->{on_fail};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_fail"} 4 2 6
419 5 ▶ $self->{on_post_hooks}->() if $self->{on_post_hooks};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_post_hooks"} 0 5 5
420 5 $self->wipe;
421  
422 5 return;
423 } ## end sub final_fail
424  
425 #=head2 exception($exc_ref)
426 #
427 #$exc_ref may be a Storable serialized value
428 #
429 #run on_exception if defined
430 #
431 #=cut
432  
433 2 ▶sub exception {
Subroutine exception: called CC=2 SCAR=7.0
Pod undocumented
434 2 my ($self, $exc_ref) = @_;
435  
436 #FIXME the only on_exception callback get dereferenced value
437 # could it be changed without damage?
438 2 my $exception = Storable::thaw($$exc_ref);
439 2 ▶ $self->{on_exception}->($$exception) if $self->{on_exception};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_exception"} 2 0 2
440 2 return;
441 } ## end sub exception
442  
443 #=head2 complete($result)
444 #
445 #C<$result> a reference profided to on_complete cb
446 #
447 #=cut
448  
449 2 ▶sub complete {
Subroutine complete: called CC=4 SCAR=14.3
Pod undocumented
450 2 my ($self, $result_ref) = @_;
451 2 ▶ return if $self->{is_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_finished"} 0 2 2
452  
453 2 $self->{is_finished} = 'complete';
454  
455 2 $self->run_hook('complete', $self);
456  
457 2 ▶ $self->{on_complete}->($result_ref) if $self->{on_complete};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_complete"} 2 0 2
458 2 ▶ $self->{on_post_hooks}->() if $self->{on_post_hooks};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_post_hooks"} 0 2 2
459 2 $self->wipe;
460 } ## end sub complete
461  
462 #=head2 status()
463 #
464 #=cut
465  
466 2 ▶sub status {
Subroutine status: called CC=3 SCAR=11.3
Pod undocumented
467 2 my $self = shift;
468 2 ▶ return if $self->{is_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_finished"} 0 2 2
469 2 ▶ return unless $self->{on_status};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"on_status"} 0 2 2
470 2 my ($nu, $de) = @_;
471 2 $self->{on_status}->($nu, $de);
472 } ## end sub status
473  
474 #=head2 data()
475 #
476 #invokes C<on_data> callback if worker sends work_data notification.
477 #
478 #=cut
479  
480 2 ▶sub data {
Subroutine data: called CC=3 SCAR=11.4
Pod undocumented
481 2 my $self = shift;
482 2 ▶ return if $self->{is_finished};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_finished"} 0 2 2
483 2 my $result_ref = shift;
484  
485 2 ▶ $self->{on_data}->($result_ref) if $self->{on_data};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"on_data"} 2 0 2
486 } ## end sub data
487  
488 #=head2 warning($message)
489 #
490 #invokes C<on_warning> callback if worker sends work_warning notification.
491 #
492 #=cut
493  
494 1 ▶sub warning {
Subroutine warning: called CC=3 SCAR=11.3
Pod undocumented
495 1 my $self = shift;
496 1 ▶ $self->{is_finished} && return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"is_finished"} and return 0 1 1
497 1 ▶ $self->{on_warning} || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"on_warning"} or return 1 0 1
498  
499 1 my $msg = shift;
500  
501 1 $self->{on_warning}->($msg);
502 } ## end sub warning
503  
504 #=head2 handle()
505 #
506 #getter
507 #
508 #=head2 handle($handle)
509 #
510 #setter for the fully-qualified handle of form "IP:port//shandle" where
511 #
512 #shandle is an opaque handle specific to the job server running on IP:port
513 #
514 #=cut
515  
516 2 ▶sub handle {
Subroutine handle: called CC=2 SCAR=7.0
Pod undocumented
517 2 my $self = shift;
518 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
519 2 $self->{handle} = shift;
520 }
521 2 return $self->{handle};
522 } ## end sub handle
523  
524  
525 # Gearman::Client::Async is the only consumer of set_on_post_hooks
526 0 ▶sub set_on_post_hooks {
Subroutine set_on_post_hooks: not called CC=1 SCAR=6.9
Pod undocumented
527 0 my ($self, $code) = @_;
528 0 $self->{on_post_hooks} = $code;
529 }
530  
531 #=head2 wipe()
532 #
533 #cleanup
534 #
535 #=over
536 #
537 #=item
538 #
539 #on_post_hooks
540 #
541 #=item
542 #
543 #on_complete
544 #
545 #=item
546 #
547 #on_fail
548 #
549 #=item
550 #
551 #on_retry
552 #
553 #=item
554 #
555 #on_status
556 #
557 #=item
558 #
559 #hooks
560 #
561 #=back
562 #
563 #=cut
564  
565 8 ▶sub wipe {
Subroutine wipe: called CC=2 SCAR=6.9
Pod undocumented
566 8 my $self = shift;
567 8 my @h = qw/
568 on_post_hooks
569 on_complete
570 on_fail
571 on_retry
572 on_status
573 hooks
574 /;
575  
576 8 foreach my $f (@h) {
577 48 $self->{$f} = undef;
578 }
579 } ## end sub wipe
580  
581 #=head2 func()
582 #
583 #=cut
584  
585 7 ▶sub func {
Subroutine func: called CC=1 SCAR=0.0
Pod undocumented
586 7 my $self = shift;
587 7 return $self->{func};
588 }
589  
590 #=head2 timeout()
591 #
592 #getter
593 #
594 #=head2 timeout($t)
595 #
596 #setter
597 #
598 #B<return> timeout
599 #
600 #=cut
601  
602 1 ▶sub timeout {
Subroutine timeout: called CC=2 SCAR=7.6
Pod undocumented
603 1 my $self = shift;
604 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
605 0 $self->{timeout} = shift;
606 }
607 1 return $self->{timeout};
608 } ## end sub timeout
609  
610 #=head2 mode()
611 #
612 #B<return> mode in depends of background and priority
613 #
614 #=cut
615  
616 15 ▶sub mode {
Subroutine mode: called CC=3 SCAR=11.0
Pod undocumented
617 15 my $self = shift;
618 15 my $mode = "submit_job";
619 15 ▶ if ($self->_priority() ne "normal") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_priority ne "normal") 6 9 15
620 6 $mode .= "_" . $self->_priority();
621 }
622  
623 15 ▶ if ($self->{background}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"background"}) 10 5 15
624 10 $mode .= "_bg";
625 }
626  
627 15 return $mode;
628 } ## end sub mode
629  
630 #=head2 _priority($priority)
631 #
632 #set/get priority
633 #
634 #valid C<$priority> value
635 #
636 #=over
637 #
638 #=item
639 #
640 #high
641 #
642 #=item
643 #
644 #normal (default)
645 #
646 #=item
647 #
648 #low
649 #
650 #=back
651 #
652 #=cut
653  
654 43 ▶sub _priority {
Subroutine _priority: called CC=5 SCAR=16.1
655 43 my ($self, $priority) = @_;
656 43 ▶ if ($self->{high_priority}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"high_priority"}) 2 41 43
657 2 warn <<'HERE';
658 Gearman::Task key high_priority is deprecated.
659 Use priority => "high" instead
660 HERE
661 2 $self->{priority} = "high";
662 2 delete($self->{high_priority});
663 } ## end if ($self->{high_priority...})
664  
665 43 ▶ if ($priority) {
Branch: 1 branch
BranchTrueFalseTotal
if ($priority) 6 37 43
666 6 ▶ $priority =~ /^(high|normal|low)$/
Branch: 1 branch
BranchTrueFalseTotal
$priority =~ /^(high|normal|low)$/ or Carp::croak("unsupported priority value") 6 0 6
667 || Carp::croak "unsupported priority value";
668 6 $self->{priority} = $priority;
669 }
670 43 ▶ $self->{priority} ||= "normal";
Condition100%2/2
$self->{"priority"} ||= "normal"
l!l
3211
MC/DC100%1/1
$self->{"priority"} ||= "normal"
$self->{"priority"}
Truth table100%2/2
A
A= $self->{"priority"}
Aresult
11
00
671  
672 43 return $self->{priority};
673 } ## end sub _priority
674  
675 7 1;
676 __END__
« Objects.pm ↑ Summary JobStatus.pm »