File Coverage

blib/lib/MangoX/Queue/Job.pm
Criterion Covered Total %
statement 3 9 33.3
branch 0 2 0.0
condition n/a
subroutine 1 3 33.3
pod 1 1 100.0
total 5 15 33.3


line stmt bran cond sub pod time code
1             package MangoX::Queue::Job;
2              
3 12     12   64 use Mojo::Base 'Mojo::EventEmitter';
  12         22  
  12         67  
4              
5             has 'has_finished' => sub { 0 };
6              
7             sub DESTROY {
8 0     0     my ($self) = @_;
9            
10 0           $self->finished;
11             }
12              
13             sub finished {
14 0     0 1   my ($self) = @_;
15              
16 0 0         return if $self->has_finished;
17 0           $self->has_finished(1);
18 0           $self->emit_safe("finished");
19             }
20              
21             1;
22              
23             =encoding utf8
24              
25             =head1 NAME
26              
27             MangoX::Queue::Job - A job consumed from L
28              
29             =head1 DESCRIPTION
30              
31             L is an object representing a job that has been consumed from L.
32             The object is just a document/job retrieved from the queue that is blessed, with an added desructor
33             method.
34              
35             This class is used internally by L
36              
37             =head1 SYNOPSIS
38              
39             use MangoX::Queue::Job;
40              
41             my $doc = {...};
42              
43             my $job = new MangoX::Queue::Job($doc);
44              
45             =head1 ATTRIBUTES
46              
47             L implements the following attributes:
48              
49             =head2 has_finished
50              
51             my $finished = $job->has_finished;
52             $job->has_finished(1);
53              
54             Is set to C<1> when the job has finished, either through the C or C methods.
55              
56             =head1 METHODS
57              
58             L implements the following methods:
59              
60             =head2 DESTROY
61              
62             Called automatically when C<$job> goes out of scope, undef'd, or refcount goes to 0.
63              
64             Calls C, emitting a C event if it hasn't already been emitted.
65              
66             =head2 finished
67              
68             Emits a C event if it hasn't already been emitted.
69              
70             =head1 SEE ALSO
71              
72             L, L, L
73              
74             =cut