line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Dancer2::Plugin::ProgressStatus::Object; |
3
|
|
|
|
|
|
|
$Dancer2::Plugin::ProgressStatus::Object::VERSION = '0.018'; |
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
292
|
use Scalar::Util qw/looks_like_number/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
137
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload |
11
|
5
|
|
|
5
|
|
1399
|
'++' => sub { my ($self, $i) = @_; $self->increment($i) }, |
|
5
|
|
|
|
|
28
|
|
12
|
0
|
|
|
0
|
|
0
|
'--' => sub { my ($self, $i) = @_; $self->decrement($i) }, |
|
0
|
|
|
|
|
0
|
|
13
|
1
|
|
|
1
|
|
6
|
'=' => sub { $_[0] }; # should never clone this object |
|
1
|
|
|
0
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
|
0
|
|
|
|
|
0
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has total => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
isa => sub { die 'total must be a number' unless looks_like_number($_[0]) }, |
18
|
|
|
|
|
|
|
default => sub { 100 } |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
has count => ( |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
isa => sub { die 'count must be a number' unless looks_like_number($_[0]) }, |
23
|
|
|
|
|
|
|
default => sub { 0 } |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
has messages => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
default => sub { [] }, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
has status => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
default => sub { 'in progress' }, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has _on_save => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
isa => sub { die 'needs _on_save coderef' unless ref($_[0]) eq 'CODE' }, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has start_time => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
default => sub { time(); } |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has current_time => ( |
46
|
|
|
|
|
|
|
is => 'rw', |
47
|
|
|
|
|
|
|
default => sub { time(); } |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
after [qw/status count/] => sub { |
51
|
|
|
|
|
|
|
if ( $_[1] ) { |
52
|
|
|
|
|
|
|
$_[0]->save(); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub finish { |
57
|
4
|
|
|
4
|
0
|
10
|
my ( $self ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
|
|
15
|
$self->save(1); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub save { |
63
|
20
|
|
|
20
|
1
|
38
|
my ( $self, $is_finished ) = @_; |
64
|
20
|
|
|
|
|
65
|
$self->current_time(time()); |
65
|
20
|
|
|
|
|
88
|
$self->_on_save->($self, $is_finished); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub increment { |
69
|
5
|
|
|
5
|
1
|
11
|
my ( $self, $increment, @messages ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
5
|
|
50
|
|
|
31
|
$increment ||= 1; |
72
|
5
|
|
|
|
|
174
|
$self->count($self->count + $increment); |
73
|
5
|
50
|
|
|
|
2839
|
if ( @messages ) { |
74
|
0
|
|
|
|
|
0
|
push @{$self->messages}, @messages; |
|
0
|
|
|
|
|
0
|
|
75
|
|
|
|
|
|
|
} |
76
|
5
|
|
|
|
|
17
|
$self->save(); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub decrement { |
80
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $increment, @messages ) = @_; |
81
|
0
|
|
0
|
|
|
0
|
$increment ||= 1; |
82
|
0
|
|
|
|
|
0
|
$self->count($self->count - $increment); |
83
|
0
|
0
|
|
|
|
0
|
if ( @messages ) { |
84
|
0
|
|
|
|
|
0
|
push @{$self->messages}, @messages; |
|
0
|
|
|
|
|
0
|
|
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
0
|
$self->save(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub add_message { |
90
|
2
|
|
|
2
|
1
|
783
|
my ( $self, @messages ) = @_; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
3
|
push @{$self->messages}, @messages; |
|
2
|
|
|
|
|
8
|
|
93
|
2
|
|
|
|
|
6
|
$self->save(); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub DESTROY { |
97
|
4
|
|
|
4
|
|
755
|
$_[0]->finish(); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
1
|
|
621
|
no Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |