File Coverage

blib/lib/Data/Perl/Role/Counter.pm
Criterion Covered Total %
statement 13 13 100.0
branch 4 4 100.0
condition n/a
subroutine 6 6 100.0
pod 4 4 100.0
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Data::Perl::Role::Counter;
2             $Data::Perl::Role::Counter::VERSION = '0.002011';
3             # ABSTRACT: Wrapping class for a simple numeric counter.
4              
5 9     9   3885 use strictures 1;
  9         85  
  9         304  
6              
7 9     9   744 use Role::Tiny;
  9         16  
  9         46  
8              
9 5     5 1 21 sub new { bless \(my $n = $_[1]), $_[0] }
10              
11 2 100   2 1 1026 sub inc { ${$_[0]} += ($_[1] ? $_[1] : 1) }
  2         9  
12              
13 2 100   2 1 480 sub dec { ${$_[0]} -= ($_[1] ? $_[1] : 1) }
  2         10  
14              
15 1     1 1 560 sub reset { ${$_[0]} = 0 }
  1         4  
16              
17             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
50              
51             Constructs a new Data::Perl::Collection::Counter object initialized with the passed
52             in value, and returns it.
53              
54             =item B
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
61              
62             =item B
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
70              
71             =item B
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
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
90              
91             =item * L
92              
93             =back
94              
95             =head1 AUTHOR
96              
97             Matthew Phillips
98              
99             =head1 COPYRIGHT AND LICENSE
100              
101             This software is copyright (c) 2020 by Matthew Phillips .
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__