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