Perfect.pm

filter: Statementstmt 81.4% 22 / 27 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 70.0% 7 / 10 Podpod 100% 6 / 6 totaltotal 70.0% 35 / 50 CC 4 SCAR 14.8
CC
4
Cov
67%
set
12.0
bump
6.0
view
2.0
CRAP 4.4
↑ Summary Minimal.pm »
1 package BRIANG::Dist::Perfect;
2  
3 3 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 BRIANG::Dist::Perfect - A perfect distribution for a perfect year. Or
11 perhaps not.
12  
13 =head1 VERSION
14  
15 This is
16 version 0.0101
17 released 2020-11-21
18  
19 =cut
20  
21 3 our $VERSION = '0.0101';
22  
23 =head1 SYNOPSIS
24  
25 # Object-oriented interface
26  
27 use BRIANG::Dist::Perfect;
28  
29 my $C1 = BRIANG::Dist::Perfect->new();
30 say $C1->peek(); # 0
31 say $C1->counter(); # 1
32 say $C1->counter(); # 2
33  
34 my $C2 = BRIANG::Dist::Perfect->new(3);
35 say $C2->peek(); # 3
36 say $C2->counter(); # 4
37 say $C2->counter(); # 5
38  
39 say $C1->counter(); # 3
40 say $C2->counter(); # 6
41  
42 # Functional interface
43  
44 use BRIANG::Dist::Perfect qw(:all);
45  
46 set(3);
47 say view(); # 3
48 say bump(); # 4
49 say view(); # 4
50 say bump(); # 5
51 say bump(); # dies
52  
53 =head1 DESCRIPTION
54  
55 This module is the principal component from the
56 C<BRIANG::Dist::Perfect> distribution.
57  
58 What a wonderful year 2020 has been, and to cap it off, here's my
59 perfect distribution.
60  
61 I intend this distribution to follow every Perl best practice I
62 can. There is a L<section below|/SEE ALSO> with an exhaustive
63 collection of documentation.
64  
65 This "dummy" module implements a counter accessible through a
66 functional or object-oriented interface.
67  
68 B<Important note regarding the functional interface>
69  
70 Due to limitations in the implementation, the functional
71 implementation cannot count beyond 5 and will throw an exception if
72 asked to do so.
73  
74 =head1 EXPORTS
75  
76 No functions are exported automaticaly, but C<bump()>, C<set()> and
77 C<view()> will be exported on request. Alternatively, the export tag
78 ':all' may be used to export all three functions.
79  
80 =cut
81  
82 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
83 3 our @EXPORT_OK = qw(bump set view);
84 3 our %EXPORT_TAGS = (all => \@EXPORT_OK);
85  
86 =head1 FUNCTIONS
87  
88 =head2 bump
89  
90 $next_counter_value = bump()
91  
92 Increases the counter by one and returns the new value.
93  
94 =head3 Exceptions Thrown
95  
96 C<Six encountered>
97  
98 =over
99  
100 Thrown whenever C<bump()> would normally have returned the value 6.
101  
102 =back
103  
104 =cut
105  
106 3 my $__count;
107  
108 0 ▶sub bump {
Subroutine bump: not called CC=2 SCAR=17.9
Pod documented
109 0 ▶ die "Six encountered"
Branch: 1 branch
BranchTrueFalseTotal
if $__count == 5 0 0 0
110 if $__count == 5;
111 0 return ++ $__count;
112 }
113  
114 =head2 set
115  
116 set($initial_value)
117  
118 Initialises the counter to C<$initial_value>, or zero if
119 C<$initial_value> is omitted.
120  
121 =head3 Exceptions Thrown
122  
123 C<Six encountered>
124  
125 =over
126  
127 Thrown whenever C<set()> is called with C<$initial_value> >= 6.
128  
129 =back
130  
131 =cut
132  
133 0 ▶sub set {
Subroutine set: not called CC=3 SCAR=24.8
Pod documented
134 0 ▶ die "Six encountered"
Branch: 1 branch
BranchTrueFalseTotal
if $__count >= 6 0 0 0
135 if $__count >= 6;
136 0 ▶ $__count = shift // 0;
Condition0%0/2
shift() // 0
l!l
00
MC/DC0%0/1
shift() // 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
137 }
138  
139 =head2 view
140  
141 $counter_value = view()
142  
143 =cut
144  
145 0 ▶sub view { $__count }
Subroutine view: not called CC=1 SCAR=6.9
Pod documented
146  
147 =head1 CONSTRUCTOR
148  
149 =head2 new
150  
151 $counter = BRIANG::Dist::Perfect->new($initial_value)
152  
153 Initialises a new counter object, and returns it. C<$initial_value> is
154 optional and is used to set an initial value for the counter. Zero is
155 used if the argument is omitted.
156  
157 =cut
158  
159 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
160 3 my ($class, $initial) = (@_, 0);
161 3 return bless {count => $initial}, $class;
162 }
163  
164 =head1 METHODS
165  
166 =head2 counter
167  
168 $next_counter_value = $counter->count()
169  
170 Adds one to the counter and returns the new value.
171  
172 =cut
173  
174 6 ▶sub counter {
Subroutine counter: called CC=1 SCAR=0.0
Pod documented
175 6 my $self = shift;
176 6 $self->{count}++;
177 6 return $self->{count};
178 }
179  
180 =head2 peek
181  
182 $counter_value = $counter->peek()
183  
184 Returns the value of the counter without incrementing its value.
185  
186 =cut
187  
188 2 ▶sub peek { shift->{count} }
Subroutine peek: called CC=1 SCAR=0.0
Pod documented
189  
190 =head1 AUTHOR, COPYRIGHT AND LICENSE
191  
192 Copyright 2020 Brian Greenfield <briang at cpan dot org>
193  
194 This is free software. You can use, redistribute, and/or modify it
195 under the terms laid out in the L<MIT licence|LICENCE>.
196  
197 =head1 SEE ALSO
198  
199 L<CPAN::Meta::Spec>
200  
201 L<ExtUtils::MakeMaker>
202  
203 L<Release::Checklist>
204  
205 L<Github Actions for Perl running on Windows, Mac OSX, and Ubuntu
206 Linux|https://perlmaven.com/github-actions-running-on-3-operating-systems>
207 by Gabor Szabo
208  
209 TODO: others?
210  
211 =head1 CODE REPOSITORY AND ISSUE REPORTING
212  
213 This project's source code is
214 L<hosted|https://github.com/briang/p5-briang-dist-perfect> on
215 L<GitHub.com|http://github.com>.
216  
217 Issues should be reported using the project's GitHub L<issue
218 tracker|https://github.com/briang/p5-briang-dist-perfect/issues>.
219  
220 Contributions are welcome. Please use L<GitHub Pull
221 Requests|https://github.com/briang/p5-briang-dist-perfect/pulls>.
222  
223 =head1 TODO: more pod???
224  
225 =cut
226  
227 3 1;
↑ Summary Minimal.pm »