JobQueue/Job.pm

filter: Statementstmt 96.3% 160 / 166 Branchbran 87.5% 35 / 40 Conditioncond 75.0% 15 / 20 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 95.7% 45 / 47 Podpod 100% 5 / 5 totaltotal 91.7% 265 / 289 CC 31 SCAR 13.3
CC
31
Cov
93%
meta_data
10.0
_modified_set
8.0
clear_modified
6.6
CRAP 3.8
« JobQueue/Util.pm ↑ Summary
1 package Redis::JobQueue::Job;
2  
3 =head1 NAME
4  
5 Redis::JobQueue::Job - Object interface for creating and manipulating jobs
6  
7 =head1 VERSION
8  
9 This documentation refers to C<Redis::JobQueue::Job> version 1.19
10  
11 =cut
12  
13 #-- Pragmas --------------------------------------------------------------------
14  
15 68 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # ENVIRONMENT ------------------------------------------------------------------
20  
21 68 our $VERSION = '1.19';
22  
23 #-- load the modules -----------------------------------------------------------
24  
25 68 ▶use Exporter qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 import
27 68 );
28 68 our @EXPORT_OK = qw(
29 STATUS_CREATED
30 STATUS_WORKING
31 STATUS_COMPLETED
32 STATUS_FAILED
33 );
34  
35 #-- load the modules -----------------------------------------------------------
36  
37 # Modules
38 68 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 68 ▶use List::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
40 min
41 68 );
42 68 ▶use Mouse; # automatically turns on strict and warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
43 68 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 68 ▶use Params::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
45 _HASH0
46 _INSTANCE
47 68 );
48 68 ▶use Time::HiRes qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 #-- declarations ---------------------------------------------------------------
51  
52 =head1 SYNOPSIS
53  
54 There are several ways to create a C<Redis::JobQueue::Job>
55 object:
56  
57 my $pre_job = {
58 id => '4BE19672-C503-11E1-BF34-28791473A258',
59 queue => 'lovely_queue',
60 job => 'strong_job',
61 expire => 12*60*60, # 12h
62 status => STATUS_CREATED,
63 workload => \'Some stuff up to 512MB long',
64 result => \'JOB result comes here, up to 512MB long',
65 };
66  
67 my $job = Redis::JobQueue::Job->new(
68 id => $pre_job->{id},
69 queue => $pre_job->{queue},
70 job => $pre_job->{job},
71 expire => $pre_job->{expire},
72 status => $pre_job->{status},
73 workload => $pre_job->{workload},
74 result => $pre_job->{result},
75 );
76  
77 $job = Redis::JobQueue::Job->new( $pre_job );
78  
79 my $next_job = Redis::JobQueue::Job->new( $job );
80  
81 Access methods to read and assign the relevant attributes of the object.
82 For example:
83  
84 $job->$workload( \'New workload' );
85 # or
86 $job->$workload( 'New workload' );
87  
88 my $id = $job->id;
89 # 'workload' and 'result' return a reference to the data
90 my $result = ${ $job->result };
91  
92 Returns a list of names of the modified object fields:
93  
94 my @modified = $job->modified_attributes;
95  
96 Resets the sign of changing an attribute. For example:
97  
98 $job->clear_modified( qw( status ) );
99  
100 =head1 DESCRIPTION
101  
102 Job API is implemented by C<Redis::JobQueue::Job> class.
103  
104 The main features of the C<Redis::JobQueue::Job> class are:
105  
106 =over 3
107  
108 =item *
109  
110 Provides an object oriented model of communication.
111  
112 =item *
113  
114 Supports data representing various aspects of the job.
115  
116 =item *
117  
118 Supports the creation of the job object, an automatic allowance for the change
119 attributes and the ability to cleanse the signs of change attributes.
120  
121 =back
122  
123 =head1 EXPORT
124  
125 None by default.
126  
127 The following additional constants, defining defaults for various parameters, are available for export:
128  
129 =over
130  
131 =item C<STATUS_CREATED>
132  
133 Initial status of the job, showing that it was created.
134  
135 =cut
136 68 ▶use constant STATUS_CREATED => '__created__';
Subroutine BEGIN: called CC=1 SCAR=0.0
137  
138 =item C<STATUS_WORKING>
139  
140 Jobs is being executed. Set by the worker function.
141  
142 =cut
143 68 ▶use constant STATUS_WORKING => '__working__';
Subroutine BEGIN: called CC=1 SCAR=0.0
144  
145 =item C<STATUS_COMPLETED>
146  
147 Job is completed. Set by the worker function.
148  
149 =cut
150 68 ▶use constant STATUS_COMPLETED => '__completed__';
Subroutine BEGIN: called CC=1 SCAR=0.0
151  
152 =item C<STATUS_FAILED>
153  
154 Job has failed. Set by the worker function.
155  
156 =cut
157 68 ▶use constant STATUS_FAILED => '__failed__';
Subroutine BEGIN: called CC=1 SCAR=0.0
158  
159 =back
160  
161 User himself should specify the status L</ STATUS_WORKING>, L</ STATUS_COMPLETED>, L</ STATUS_FAILED>
162 or own status when processing the job.
163  
164 =cut
165  
166 68 my $meta = __PACKAGE__->meta;
167  
168 subtype __PACKAGE__.'::NonNegInt',
169 as 'Int',
170 53 ▶ where { $_ >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
171 0 ▶ message { ( $_ || '' ).' is not a non-negative integer!' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_ || ''
l!l
00
MC/DC0%0/1
$_ || ''
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
172 68 ;
173  
174 subtype __PACKAGE__.'::NonNegNum',
175 as 'Num',
176 230 ▶ where { $_ >= 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
177 24 ▶ message { ( $_ || '' ).' is not a non-negative number!' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_ || ''
l!l
204
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
178 68 ;
179  
180 subtype __PACKAGE__.'::Progress',
181 as 'Num',
182 45 ▶ where { $_ >= 0 and $_ <= 1 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 0 and $_ <= 1 43 2 45
183 7 ▶ message { ( $_ || '' ).' is not a progress number!' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_ || ''
l!l
52
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
184 68 ;
185  
186 subtype __PACKAGE__.'::WOSpStr',
187 as 'Str',
188 65 ▶ where { $_ !~ / / },
Subroutine __ANON__: called CC=1 SCAR=0.0
189 3 ▶ message { ( $_ || '' ).' contains spaces!' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_ || ''
l!l
21
MC/DC100%1/1
$_ || ''
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
190 68 ;
191  
192 68 subtype __PACKAGE__.'::DataRef',
193 as 'ScalarRef'
194 ;
195  
196 coerce __PACKAGE__.'::DataRef',
197 from 'Str',
198 4 ▶ via { \$_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
199 68 ;
200  
201 #-- constructor ----------------------------------------------------------------
202  
203 =head2 CONSTRUCTOR
204  
205 An error will cause the program to halt if the argument is not valid.
206  
207 =head3 C<new( id =E<gt> $uuid, ... )>
208  
209 It generates a Job object and can be called as either a class method or
210 an object method.
211  
212 If invoked with the first argument being an object of C<Redis::JobQueue::Job> class
213 or a reference to a hash, then the new object attribute values are taken from
214 the hash of the first argument.
215  
216 C<new> optionally takes arguments. These arguments are in key-value pairs.
217  
218 This example illustrates a C<new()> call with all the valid arguments:
219  
220 $job = Redis::JobQueue::Job->new(
221 id => '4BE19672-C503-11E1-BF34-28791473A258',
222 # UUID string, using conventional UUID string format.
223 # Do not use it because filled in automatically when
224 # you create a job.
225 queue => 'lovely_queue', # The name of the job queue.
226 # (required)
227 job => 'strong_job', # The name of the job.
228 # (optional attribute)
229 expire => 12*60*60, # Job's time to live in seconds.
230 # 0 for no expire time.
231 # (required)
232 status => STATUS_CREATED, # Current status of the job.
233 # Do not use it because value should be set by the worker.
234 workload => \'Some stuff up to 512MB long',
235 # Baseline data for the function of the worker
236 # (the function name specified in the 'job').
237 # Can be a scalar, an object or a reference to a scalar, hash, or array
238 result => \'JOB result comes here, up to 512MB long',
239 # The result of the function of the worker
240 # (the function name specified in the 'job').
241 # Do not use it because value should be set by the worker.
242 );
243  
244 Returns the object itself, we can chain settings.
245  
246 The attributes C<workload> and C<result> may contain a large amount of data,
247 therefore, it is desirable that they be passed as references to the actual
248 data to improve performance.
249  
250 Do not use spaces in an C<id> attribute value.
251  
252 Each element in the struct data has an accessor method, which is
253 used to assign and fetch the element's value.
254  
255 =cut
256 66 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
257 66 my $orig = shift;
258 66 my $class = shift;
259  
260 66 ▶ if ( _INSTANCE( $_[0], __PACKAGE__ ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_INSTANCE($_[0], __PACKAGE__)) { } 2 64 66
261 2 my $job = shift;
262 2 return $class->$orig( ( map { ( $_, $job->$_ ) } $job->job_attributes ), @_ );
263 } else {
264 64 return $class->$orig( @_ );
265 }
266 68 };
267  
268 #-- public attributes ----------------------------------------------------------
269  
270 =head2 METHODS
271  
272 An error will cause the program to halt if the argument is not valid.
273  
274 =head3 C<id>
275  
276 =head3 C<queue>
277  
278 =head3 C<job>
279  
280 =head3 C<expire>
281  
282 =head3 C<status>
283  
284 =head3 C<workload>
285  
286 =head3 C<result>
287  
288 The family of methods for a multitude of accessor methods for your data with
289 the appropriate names. These methods are able to read and assign the relevant
290 attributes of the object.
291  
292 As attributes C<workload> and C<result> may contain a large amount of data
293 (scalars, references to arrays and hashes, objects):
294  
295 =over 3
296  
297 =item *
298  
299 A read method returns a reference to the data.
300  
301 =item *
302  
303 A write method can receive both data or a reference to the data.
304  
305 =back
306  
307 =cut
308 has 'id' => (
309 is => 'rw',
310 isa => __PACKAGE__.'::WOSpStr',
311 default => '',
312 16 ▶ trigger => sub { $_[0]->_modified_set( 'id' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
313 68 );
314  
315 has 'queue' => (
316 is => 'rw',
317 isa => 'Maybe[Str]',
318 required => 1,
319 16 ▶ trigger => sub { $_[0]->_modified_set( 'queue' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
320 68 );
321  
322 has 'job' => (
323 is => 'rw',
324 isa => 'Maybe[Str]',
325 default => '',
326 16 ▶ trigger => sub { $_[0]->_modified_set( 'job' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
327 68 );
328  
329 has 'status' => (
330 is => 'rw',
331 isa => 'Str',
332 default => STATUS_CREATED,
333 19 ▶ trigger => sub { $_[0]->_modified_set( 'status', $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
334 68 );
335  
336 has 'expire' => (
337 is => 'rw',
338 isa => 'Maybe['.__PACKAGE__.'::NonNegInt]',
339 required => 1,
340 16 ▶ trigger => sub { $_[0]->_modified_set( 'expire' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
341 68 );
342  
343 68 for my $name ( qw( workload result ) ) {
344 has $name => (
345 is => 'rw',
346 # A reference because attribute can contain a large amount of data
347 isa => __PACKAGE__.'::DataRef | HashRef | ArrayRef | ScalarRef | Object',
348 coerce => 1,
349 builder => '_build_data', # will throw an error if you pass a bare non-subroutine reference as the default
350 34 ▶ trigger => sub { $_[0]->_modified_set( $name ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
351 136 );
352 }
353  
354 =head3 C<progress>
355  
356 Optional attribute, the progress of the task,
357 contains a user-defined value from 0 to 1.
358  
359 =cut
360 has 'progress' => (
361 is => 'rw',
362 isa => __PACKAGE__.'::Progress',
363 default => 0,
364 5 ▶ trigger => sub { $_[0]->_modified_set( 'progress' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
365 68 );
366  
367 =head3 C<message>
368  
369 Optional attribute, a string message with additional user-defined information.
370  
371 =cut
372 has 'message' => (
373 is => 'rw',
374 isa => 'Maybe[Str]',
375 default => '',
376 5 ▶ trigger => sub { $_[0]->_modified_set( 'message' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
377 68 );
378  
379 =head3 C<created>
380  
381 Returns time of job creation.
382 Set to the current time (C<Time::HiRes::time>) when job is created.
383  
384 If necessary, alternative value can be set as:
385  
386 $job->created( time );
387  
388 =head3 C<updated>
389  
390 Returns the time of the most recent modification of the job.
391  
392 Set to the current time (C<Time::HiRes::time>) when value(s) of any of the following data changes:
393 L</status>, L</workload>, L</result>, L</progress>, L</message>, L</completed>, L</failed>.
394  
395 Can be updated manually:
396  
397 $job->updated( time );
398  
399 =cut
400 68 for my $name ( qw( created updated ) ) {
401 has $name => (
402 is => 'rw',
403 isa => __PACKAGE__.'::NonNegNum',
404 52 ▶ default => sub { Time::HiRes::time },
Subroutine __ANON__: called CC=1 SCAR=0.0
405 97 ▶ trigger => sub { $_[0]->_modified_set( $name ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
406 136 );
407 }
408  
409 =head3 C<started>
410  
411 Returns the time that the job started processing.
412 Set to the current time (C<Time::HiRes::time>) when the L</status> of the job is set to L</STATUS_WORKING>.
413  
414 If necessary, you can set your own value, for example:
415  
416 $job->started( time );
417  
418 =head3 C<completed>
419  
420 Returns the time of the task completion.
421  
422 It is set to 0 when task is created.
423  
424 Set to C<Time::HiRes::time> when L</status> is changed to L</STATUS_COMPLETED>.
425  
426 Can be modified manually:
427  
428 $job->completed( time );
429  
430 Change the C<completed> attribute sets C<failed> = 0.
431 The attributes C<completed> and C<failed> are mutually exclusive.
432  
433 =head3 C<failed>
434  
435 Returns the time of the task failure.
436  
437 It is set to 0 when task is created.
438  
439 Set to C<Time::HiRes::time> when L</status> is changed to L</STATUS_FAILED>.
440  
441 Can be modified manually:
442  
443 $job->failed( time );
444  
445 Change the C<failed> attribute sets C<completed> = 0.
446 The attributes C<failed> and C<completed> are mutually exclusive.
447  
448 =cut
449 68 for my $name ( qw( started completed failed ) ) {
450 has $name => (
451 is => 'rw',
452 isa => __PACKAGE__.'::NonNegNum',
453 default => 0,
454 22 ▶ trigger => sub { $_[0]->_modified_set( $name ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
455 204 );
456 }
457  
458 #-- private attributes ---------------------------------------------------------
459  
460 has '_meta_data' => (
461 is => 'rw',
462 isa => 'HashRef',
463 init_arg => 'meta_data',
464 11 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
465 68 );
466  
467 68 has '__modified' => (
468 is => 'ro',
469 isa => 'HashRef[Int]',
470 lazy => 1,
471 init_arg => undef, # we make it impossible to set this attribute when creating a new object
472 builder => '_build_modified',
473 );
474  
475 has '__modified_meta_data' => (
476 is => 'rw',
477 isa => 'HashRef[Int]',
478 lazy => 1,
479 init_arg => undef, # we make it impossible to set this attribute when creating a new object
480 3 ▶ default => sub { return {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
481 68 );
482  
483 #-- public methods -------------------------------------------------------------
484  
485 =head3 C<elapsed>
486  
487 Returns the time (a floating seconds since the epoch) since the job started processing (see L</started>)
488 till job L</completed> or L</failed> or to the current time.
489 Returns C<undef> if the start processing time was set to 0.
490  
491 =cut
492 6 ▶sub elapsed {
Subroutine elapsed: called CC=4 SCAR=13.9
Pod documented
493 6 my ( $self ) = @_;
494  
495 6 ▶ if ( my $started = $self->started ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $started = $self->started) { } 3 3 6
496 3 ▶ return( ( $self->completed || $self->failed || Time::HiRes::time ) - $started );
Condition83%5/6
$self->completed || $self->failed || &Time::HiRes::time()
l!l&&r!l&&!r
210
$self->completed or $self->failed
l!l&&r!l&&!r
111
MC/DC0%0/3
$self->completed || $self->failed || &Time::HiRes::time()
$self->completed $self->failed &Time::HiRes::time()
Truth table75%3/4
A or B || C
A= $self->completedB= $self->failedC= &Time::HiRes::time()
ABCresult
1XX1
01X1
0011
0000
497 } else {
498 3 return( undef );
499 }
500 }
501  
502 =head3 C<meta_data>
503  
504 With no arguments, returns a reference to a hash of metadata (additional information related to the job).
505 For example:
506  
507 my $md = $job->meta_data;
508  
509 Hash value of an individual item metadata is available by specifying the name of the hash key.
510 For example:
511  
512 my $foo = $job->meta_data( 'foo' );
513  
514 Separate metadata value can be set as follows:
515  
516 my $foo = $job->meta_data( next => 16 );
517  
518 Group metadata can be specified by reference to a hash.
519 Metadata may contain scalars, references to arrays and hashes, objects.
520 For example:
521  
522 $job->meta_data(
523 {
524 'foo' => 12,
525 'bar' => [ 13, 14, 15 ],
526 'other' => { a => 'b', c => 'd' },
527 }
528 );
529  
530 The name of the metadata fields should not match the standard names returned by
531 L</job_attributes> and must not begin with C<'__'}>.
532 An invalid name causes die (C<confess>).
533  
534 =cut
535 68 ▶my %_attributes = map { ( $_->name eq '_meta_data' ? 'meta_data' : $_->name ) => 1 } grep { substr( $_->name, 0, 2 ) ne '__' } $meta->get_all_attributes;
Branch: 1 branch
BranchTrueFalseTotal
$_->name eq '_meta_data' ? : 68 952 1020
536  
537 46 ▶sub meta_data {
Subroutine meta_data: called CC=10 SCAR=23.1
Pod documented
538 46 my ( $self, $key, $val ) = @_;
539  
540 46 ▶ return $self->_meta_data
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 11 35 46
541 if !defined $key;
542  
543 # metadata can be set with an external hash
544 35 ▶ if ( _HASH0( $key ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_HASH0($key)) 16 19 35
545 16 foreach my $field ( keys %$key ) {
546 confess 'The name of the metadata field the same as standart job field name'
547 17 ▶ if exists $_attributes{ $field } || substr( $field, 0, 2 ) eq '__';
Branch: 1 branch
BranchTrueFalseTotal
if exists $_attributes{$field} or substr($field, 0, 2) eq "__" 15 2 17
Condition66%2/3
exists $_attributes{$field} or substr($field, 0, 2) eq "__"
l!l&&r!l&&!r
1502
MC/DC50%1/2
exists $_attributes{$field} or substr($field, 0, 2) eq "__"
exists $_attributes{$field} substr($field, 0, 2) eq "__"
Truth table66%2/3
A or B
A= exists $_attributes{$field}B= substr($field, 0, 2) eq "__"
ABresult
1X1
011
000
548 }
549 1 $self->_meta_data( $key );
550 1 $self->__modified_meta_data( {} );
551 $self->__modified_meta_data->{ $_ } = 1
552 1 foreach keys %$key;
553 1 return;
554 }
555  
556 # getter
557 19 ▶ return $self->_meta_data->{ $key }
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 2 17 19
558 if !defined $val;
559  
560 # setter
561 confess 'The name of the metadata field the same as standart job field name'
562 17 ▶ if exists $_attributes{ $key } || substr( $key, 0, 2 ) eq '__';
Branch: 1 branch
BranchTrueFalseTotal
if exists $_attributes{$key} or substr($key, 0, 2) eq "__" 15 2 17
Condition66%2/3
exists $_attributes{$key} or substr($key, 0, 2) eq "__"
l!l&&r!l&&!r
1502
MC/DC50%1/2
exists $_attributes{$key} or substr($key, 0, 2) eq "__"
exists $_attributes{$key} substr($key, 0, 2) eq "__"
Truth table66%2/3
A or B
A= exists $_attributes{$key}B= substr($key, 0, 2) eq "__"
ABresult
1X1
011
000
563 2 $self->_meta_data->{ $key } = $val;
564 2 ++$self->__modified_meta_data->{ $key };
565  
566 # job data change
567 2 $self->updated( Time::HiRes::time );
568 2 ++$self->__modified->{ 'updated' };
569  
570 2 return;
571 }
572  
573 =head3 C<clear_modified( @fields )>
574  
575 Resets the sign of any specified attributes that have been changed.
576 If no attribute names are specified, the signs are reset for all attributes.
577  
578 =cut
579 47 ▶sub clear_modified {
Subroutine clear_modified: called CC=6 SCAR=18.8
Pod documented
580 47 my ( $self, @fields ) = @_;
581  
582 47 ▶ unless ( @fields ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@fields) 15 32 47
583 15 $self->clear_modified( $self->job_attributes );
584 15 my @keys = keys %{ $self->__modified_meta_data };
585 15 ▶ $self->clear_modified( @keys )
Branch: 1 branch
BranchTrueFalseTotal
if @keys 0 15 15
586 if @keys;
587 15 return;
588 }
589  
590 32 foreach my $field ( @fields ) {
591 256 ▶ if ( exists $self->__modified->{ $field } ) { $self->__modified->{ $field } = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->__modified->{$field}) { } 256 0 256
elsif (exists $self->__modified_meta_data->{$field}) { } 0 0 0
592 0 elsif ( exists $self->__modified_meta_data->{ $field } ) { $self->__modified_meta_data->{ $field } = 0 }
593 }
594  
595 32 return;
596 }
597  
598 =head3 C<modified_attributes>
599  
600 Returns a list of names of the object attributes that have been modified.
601  
602 =cut
603 31 ▶sub modified_attributes {
Subroutine modified_attributes: called CC=1 SCAR=0.0
Pod documented
604 31 my ( $self ) = @_;
605  
606 my @all_modified = (
607 465 grep( { $self->__modified->{ $_ } } $self->job_attributes ),
608 0 grep( { $self->__modified_meta_data->{ $_ } } keys( %{ $self->__modified_meta_data } ) ),
609 );
610  
611 31 return @all_modified;
612 }
613  
614 =head3 C<job_attributes>
615  
616 Returns a sorted list of the names of object attributes.
617  
618 =cut
619 130 ▶sub job_attributes {
Subroutine job_attributes: called CC=1 SCAR=0.0
Pod documented
620 130 return( sort keys %_attributes );
621 }
622  
623 #-- private methods ------------------------------------------------------------
624  
625 0 ▶sub _build_data {
Subroutine _build_data: not called CC=1 SCAR=6.9
626 0 my $empty_data = q{};
627 0 return \$empty_data;
628 }
629  
630 14 ▶sub _build_modified {
Subroutine _build_modified: called CC=1 SCAR=0.0
631 14 my ( $self ) = @_;
632  
633 14 my %modified;
634 14 map { $modified{ $_ } = 1 } $self->job_attributes;
635 14 return \%modified;
636 }
637  
638 246 ▶sub _modified_set {
Subroutine _modified_set: called CC=8 SCAR=20.8
639 246 my $self = shift;
640 246 my $field = shift;
641  
642 246 ▶ if ( $field =~ /^(status|meta_data|workload|result|progress|message|started|completed|failed)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(status|meta_data|workload|result|progress|message|started|completed|failed)$/) 85 161 246
643 85 $self->updated( Time::HiRes::time );
644 85 ++$self->__modified->{ 'updated' };
645 }
646  
647 246 ▶ if ( $field eq 'status' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "status") 19 227 246
648 19 my $new_status = shift;
649 0 ▶ if ( $new_status eq STATUS_CREATED ) { $self->created( Time::HiRes::time ) }
Branch: 4 branches
BranchTrueFalseTotal
if ($new_status eq '__created__') { } 0 19 19
elsif ($new_status eq '__working__') { } 4 15 19
elsif ($new_status eq '__completed__') { } 2 13 15
elsif ($new_status eq '__failed__') { } 2 11 13
650 4 ▶ elsif ( $new_status eq STATUS_WORKING ) { $self->started( Time::HiRes::time ) unless $self->started }
Branch: 1 branch
BranchTrueFalseTotal
unless $self->started 3 1 4
651 2 elsif ( $new_status eq STATUS_COMPLETED ) { $self->completed( Time::HiRes::time ) }
652 2 elsif ( $new_status eq STATUS_FAILED ) { $self->failed( Time::HiRes::time ) }
653 }
654  
655 246 ++$self->__modified->{ $field };
656  
657 246 return;
658 }
659  
660 #-- Closes and cleans up -------------------------------------------------------
661  
662 68 ▶no Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
663 68 ▶no Mouse; # keywords are removed from the package
Subroutine BEGIN: called CC=1 SCAR=0.0
664 68 __PACKAGE__->meta->make_immutable();
665  
666 __END__
« JobQueue/Util.pm ↑ Summary