| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Counter; |
|
2
|
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
118628
|
use Catmandu::Sane; |
|
|
24
|
|
|
|
|
70
|
|
|
|
24
|
|
|
|
|
246
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
24
|
|
|
24
|
|
182
|
use Moo::Role; |
|
|
24
|
|
|
|
|
59
|
|
|
|
24
|
|
|
|
|
197
|
|
|
8
|
24
|
|
|
24
|
|
8796
|
use namespace::clean; |
|
|
24
|
|
|
|
|
74
|
|
|
|
24
|
|
|
|
|
175
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has count => (is => 'rwp', default => sub {0}); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub inc_count { |
|
13
|
359
|
|
|
359
|
1
|
4302
|
my ($self, $n) = @_; |
|
14
|
359
|
|
100
|
|
|
2062
|
$n //= 1; |
|
15
|
359
|
|
|
|
|
6917
|
$self->_set_count($self->count + $n); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub dec_count { |
|
19
|
2
|
|
|
2
|
1
|
1593
|
my ($self, $n) = @_; |
|
20
|
2
|
|
50
|
|
|
12
|
$n //= 1; |
|
21
|
2
|
|
|
|
|
20
|
my $count = $self->count - $n; |
|
22
|
2
|
50
|
|
|
|
11
|
$self->_set_count($count > 0 ? $count : 0); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub reset_count { |
|
26
|
1
|
|
|
1
|
1
|
13
|
my $self = $_[0]; |
|
27
|
1
|
|
|
|
|
5
|
$self->_set_count(0); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=pod |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Catmandu::Counter - A Base class for modules who need to count things |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package MyPackage; |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Moo; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
with 'Catmandu::Counter'; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub calculate { |
|
49
|
|
|
|
|
|
|
my ($self) = @_; |
|
50
|
|
|
|
|
|
|
$self->inc_count; |
|
51
|
|
|
|
|
|
|
#...do stuff |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
package main; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $x = MyPackage->new; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$x->calculate; |
|
59
|
|
|
|
|
|
|
$x->calculate; |
|
60
|
|
|
|
|
|
|
$x->calculate; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
print "Executed calculate %d times\n" , $x->count; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 count |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The current value of the counter. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 METHODS |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 inc_count() |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 inc_count(NUMBER) |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Increment the counter. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 dec_count() |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 dec_count(NUMBER) |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Decrement the counter. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 reset_count() |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Reset the counter to zero. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<Catmandu::Exporter> |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |