line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BRIANG::Dist::Perfect; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
209325
|
use 5.10.1; |
|
3
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
80
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
192
|
|
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
|
|
|
|
|
|
|
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 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 |
63
|
|
|
|
|
|
|
collection of documentation. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This "dummy" module implements a counter accessible through a |
66
|
|
|
|
|
|
|
functional or object-oriented interface. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
B |
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, C and |
77
|
|
|
|
|
|
|
C 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
|
|
|
3
|
|
1406
|
use parent 'Exporter'; |
|
3
|
|
|
|
|
919
|
|
|
3
|
|
|
|
|
15
|
|
83
|
|
|
|
|
|
|
our @EXPORT_OK = qw(bump set view); |
84
|
|
|
|
|
|
|
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 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Thrown whenever C would normally have returned the value 6. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $__count; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub bump { |
109
|
0
|
0
|
|
0
|
1
|
0
|
die "Six encountered" |
110
|
|
|
|
|
|
|
if $__count == 5; |
111
|
0
|
|
|
|
|
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 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=over |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Thrown whenever C is called with C<$initial_value> >= 6. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=back |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub set { |
134
|
0
|
0
|
|
0
|
1
|
0
|
die "Six encountered" |
135
|
|
|
|
|
|
|
if $__count >= 6; |
136
|
0
|
|
0
|
|
|
0
|
$__count = shift // 0; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 view |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$counter_value = view() |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
0
|
1
|
0
|
sub view { $__count } |
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
|
|
|
|
|
|
|
sub new { |
160
|
3
|
|
|
3
|
1
|
189
|
my ($class, $initial) = (@_, 0); |
161
|
3
|
|
|
|
|
14
|
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
|
|
|
|
|
|
|
sub counter { |
175
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
176
|
6
|
|
|
|
|
8
|
$self->{count}++; |
177
|
6
|
|
|
|
|
24
|
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
|
|
|
2
|
1
|
20
|
sub peek { shift->{count} } |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT AND LICENSE |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Copyright 2020 Brian Greenfield |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
This is free software. You can use, redistribute, and/or modify it |
195
|
|
|
|
|
|
|
under the terms laid out in the L. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 SEE ALSO |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
L |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L
|
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 on |
215
|
|
|
|
|
|
|
L. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Issues should be reported using the project's GitHub L
|
218
|
|
|
|
|
|
|
tracker|https://github.com/briang/p5-briang-dist-perfect/issues>. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Contributions are welcome. Please use L
|
221
|
|
|
|
|
|
|
Requests|https://github.com/briang/p5-briang-dist-perfect/pulls>. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 TODO: more pod??? |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |