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