Perl/Role/Counter.pm

filter: Statementstmt 100% 15 / 15 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 100% 29 / 29 CC 3 SCAR 4.1
CC
3
Cov
100%
inc
2.0
dec
2.0
BEGIN
1.0
CRAP 1.5
« Perl/Role/Collection/Hash.pm ↑ Summary Perl/Role/String.pm »
1 package Data::Perl::Role::Counter;
2 9 $Data::Perl::Role::Counter::VERSION = '0.002011';
3 # ABSTRACT: Wrapping class for a simple numeric counter.
4  
5 9 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶sub new { bless \(my $n = $_[1]), $_[0] }
Subroutine new: called CC=1 SCAR=0.0
Pod documented
10  
11 2 ▶sub inc { ${$_[0]} += ($_[1] ? $_[1] : 1) }
Subroutine inc: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 1 1 2
12  
13 2 ▶sub dec { ${$_[0]} -= ($_[1] ? $_[1] : 1) }
Subroutine dec: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 1 1 2
14  
15 1 ▶sub reset { ${$_[0]} = 0 }
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
16  
17 9 1;
18  
19 =pod
20  
21 =encoding UTF-8
22  
23 =head1 NAME
24  
25 Data::Perl::Role::Counter - Wrapping class for a simple numeric counter.
26  
27 =head1 VERSION
28  
29 version 0.002011
30  
31 =head1 SYNOPSIS
32  
33 use Data::Perl qw/counter/;
34  
35 my $c = counter(4);
36  
37 $c->inc; # $c == 5
38  
39 $c->reset; # $c == 0
40  
41 =head1 DESCRIPTION
42  
43 This class provides a wrapper and methods for a simple numeric counter.
44  
45 =head1 PROVIDED METHODS
46  
47 =over 4
48  
49 =item B<new($value)>
50  
51 Constructs a new Data::Perl::Collection::Counter object initialized with the passed
52 in value, and returns it.
53  
54 =item B<set($value)>
55  
56 Sets the counter to the specified value and returns the new value.
57  
58 This method requires a single argument.
59  
60 =item B<inc>
61  
62 =item B<inc($arg)>
63  
64 Increases the attribute value by the amount of the argument, or by 1 if no
65 argument is given. This method returns the new value.
66  
67 This method accepts a single argument.
68  
69 =item B<dec>
70  
71 =item B<dec($arg)>
72  
73 Decreases the attribute value by the amount of the argument, or by 1 if no
74 argument is given. This method returns the new value.
75  
76 This method accepts a single argument.
77  
78 =item B<reset>
79  
80 Resets the value stored in this slot to its default value, and returns the new
81 value.
82  
83 =back
84  
85 =head1 SEE ALSO
86  
87 =over 4
88  
89 =item * L<Data::Perl>
90  
91 =item * L<MooX::HandlesVia>
92  
93 =back
94  
95 =head1 AUTHOR
96  
97 Matthew Phillips <mattp@cpan.org>
98  
99 =head1 COPYRIGHT AND LICENSE
100  
101 This software is copyright (c) 2020 by Matthew Phillips <mattp@cpan.org>.
102  
103 This is free software; you can redistribute it and/or modify it under
104 the same terms as the Perl 5 programming language system itself.
105  
106 =cut
107  
108 __END__
« Perl/Role/Collection/Hash.pm ↑ Summary Perl/Role/String.pm »