FishFarm/WaterFiltration.pm

filter: Statementstmt 95.4% 63 / 66 Branchbran 66.6% 28 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 100% 13 / 13 totaltotal 87.0% 121 / 139 CC 22 SCAR 11.8
CC
22
Cov
84%
clean_cylinder
7.1
turn_off_spatulas
6.0
current_waste_count
3.0
CRAP 3.2
« FishFarm/Feeder.pm ↑ Summary FishFarm.pm »
1 package Acme::FishFarm::WaterFiltration;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp "croak";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Acme::FishFarm::WaterFiltration - Water Filter for Acme::FishFarm
11  
12 =head1 VERSION
13  
14 Version 1.00
15  
16 =cut
17  
18 3 our $VERSION = '1.00';
19  
20  
21 =head1 SYNOPSIS
22  
23 use Acme::FishFarm::WaterFiltration;
24 # missing stuff will be added in the next release
25  
26 =head1 EXPORT
27  
28 None
29  
30 =head1 DESCRIPTION
31  
32 This module assumes a cool water filter with a filtering cylinder constantly filtering water in
33 the tank. It has inlet, outlet and a drainage valves. The drainage valve is only opened when the
34 cleaners are switched on automatically to remove waste from the cylinder. To be honest, those cleaners look more like spatulas to me :)
35  
36 This feature is based on the water filter found L<here|https://www.filternox.com/filters/spt-wbv-mr/>
37  
38 =head1 CREATION SUBROUTINES/METHODS
39  
40 =head2 install ( %options )
41  
42 Installs a cool water filtration system.
43  
44 The following are avaiable for C<%options>:
45  
46 =over 4
47  
48 =item current_waste_count
49  
50 The current waste count in the cylinder. Default is C<0>.
51  
52 =item waste_threshold
53  
54 Default value is C<75>.
55  
56 Sets the waste treshold.
57  
58 This is the maximum limit of waste in the cylinder. When this count is hit, it will turn on the cleaners / spatulas or whatever it's called :).
59  
60 =item reduce_waste_count_by
61  
62 Default is 10.
63  
64 The amount of waste to remove from the cylinder / filter each time the cleaning process is called.
65  
66 =back
67  
68 =cut
69  
70 sub install {
71 3 ▶ my $class = shift;
Subroutine install: called CC=3 SCAR=11.0
Pod documented
72 3 my %options = @_;
73
74 3 ▶ if ( not $options{current_waste_count} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"current_waste_count"}) 2 1 3
75 2 $options{current_waste_count} = 0;
76 }
77
78 3 ▶ if ( not $options{waste_threshold} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"waste_threshold"}) 2 1 3
79 2 $options{waste_threshold} = 75;
80 }
81
82 3 $options{is_on_spatulas} = 0;
83 3 $options{reduce_waste_count_by} = 10;
84
85 3 bless \%options, "Acme::FishFarm::WaterFiltration";
86 }
87  
88  
89 =head1 WASTE LEVEL DETECTING SUBROUTINES/METHODS
90  
91 =head2 current_waste_count ( $new_waste_count )
92  
93 Sets / returns the current waste count inside the cylinder.
94  
95 C<$new_waste_count> is optional. If present, the current waste count will be set to C<$new_waste_count>. Otherwise, returns the current waste count.
96  
97 =cut
98  
99 sub current_waste_count {
100 14 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine current_waste_count: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 14 14
101
102 14 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 6 8 14
103 6 $self->{current_waste_count} = shift;
104 } else {
105 8 $self->{current_waste_count};
106 }
107 }
108  
109 =head2 waste_count_threshold
110  
111 Returns the waste count threshold.
112  
113 =cut
114  
115 sub waste_count_threshold {
116 4 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine waste_count_threshold: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 4 4
117 4 $self->{waste_threshold};
118 }
119  
120 =head2 set_waste_count_threshold
121  
122 Sets the waste count threshold.
123  
124 =cut
125  
126 sub set_waste_count_threshold {
127 1 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine set_waste_count_threshold: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 1 1
128 1 $self->{waste_threshold} = shift;
129 }
130  
131 =head2 reduce_waste_count_by
132  
133 Returns the amount of waste to be reduce each time the cleaning process is called.
134  
135 =cut
136  
137 sub reduce_waste_count_by {
138 4 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine reduce_waste_count_by: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 4 4
139 4 $self->{reduce_waste_count_by};
140 }
141  
142 =head2 set_waste_count_to_reduce ( $new_count )
143  
144 Sets the waste count reduction value to C<$new_count>.
145  
146 =cut
147  
148 sub set_waste_count_to_reduce {
149 1 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine set_waste_count_to_reduce: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 1 1
150 1 $self->{reduce_waste_count_by} = shift;
151 }
152  
153 =head2 is_filter_layer_dirty
154  
155 Synonym for C<is_cylinder_dirty>. See next method.
156  
157 =head2 is_cylinder_dirty
158  
159 Returns C<1> if the filtering cylinder is dirty ie current waste count hits the waste count threshold. Returns C<0> otherwise.
160  
161 Remember to clean your cylinder ie. filter layer as soon as possible.
162  
163 =cut
164  
165 sub is_filter_layer_dirty {
166 3 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine is_filter_layer_dirty: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 3 3
167 3 $self->is_cylinder_dirty;
168 }
169  
170 sub is_cylinder_dirty {
171 6 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine is_cylinder_dirty: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 6 6
172 6 ▶ if ( $self->{current_waste_count} >= $self->{waste_threshold} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current_waste_count'} >= $self->{'waste_threshold'}) { } 4 2 6
173 4 return 1;
174 } else {
175 2 return 0;
176 }
177 }
178  
179 =head1 CLEANING RELATED SUBROUTINES/METHODS
180  
181 =head2 clean_filter_layer
182  
183 Synonym for C<is_cylinder_dirty>. See next method.
184  
185 =cut
186  
187 sub clean_filter_layer {
188 1 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine clean_filter_layer: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 1 1
189 1 $self->clean_cylinder(@_);
190 }
191  
192 =head2 clean_cylinder ( $reduce_waste_by )
193  
194 Cleans the filter layer in the cylinder.
195  
196 C<$reduce_waste_by> is optional. If present, it will reduce waste by that specific value. Otherwise, it cleans the cylinder completly in one shot ie waste count will be C<0>.
197  
198 If C<$reduce_waste_by> is a negative value, it will be turned into a positive value with the same magnitude.
199  
200 Make sure that you turn on your spatula, if not this process will not do anything :)
201  
202 =cut
203  
204 sub clean_cylinder {
205 3 ▶ no warnings "numeric";
Subroutine BEGIN: called CC=1 SCAR=0.0
206 5 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine clean_cylinder: called CC=7 SCAR=19.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 5 5
207
208 5 my $reduce_waste_by;
209 5 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 3 5
210 2 my $reduce = shift;
211 2 ▶ if ( $reduce < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reduce < 0) { } 1 1 2
212 1 $reduce_waste_by = abs($reduce);
213 # futhre error checking is done in Acme::FishFarm::check_water_filter
214 } else {
215 1 $reduce_waste_by = $reduce;
216 }
217 } else {
218 3 $reduce_waste_by = 0;
219 }
220
221 5 ▶ if ( $self->{is_on_spatulas} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'is_on_spatulas'}) { } 4 1 5
222
223 4 ▶ if ( $reduce_waste_by ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reduce_waste_by) { } 2 2 4
224 #reduce based on user input
225 2 ▶ if ( $self->{current_waste_count} > $reduce_waste_by ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current_waste_count'} > $reduce_waste_by) { } 2 0 2
226 2 $self->{current_waste_count} -= $reduce_waste_by;
227 } else {
228 # $reduce_waste_by not specified
229 0 $self->{current_waste_count} = 0;
230 }
231 } else {
232 2 $self->{current_waste_count} = 0;
233 }
234
235 } else {
236 1 return;
237 }
238 }
239  
240 =head2 turn_on_spatulas
241  
242 Activates the cleaning mechanism ie the spatulas :)
243  
244 Take note that turning on the spatulas does not clean the cylinder. You need to do it explicitly. See C<clean_cylinder> method for more info :)
245  
246 =head2 turn_off_spatulas
247  
248 Deactivates the cleaning mechanism ie the spatulas :)
249  
250 See C<clean_cylinder> method for more info :)
251  
252 =head2 is_on_spatulas
253  
254 Returns C<1> if the spatula are turned on. The spatula will not clean the cylinder until you explicitly tell the system to do so. See C<clean_cylinder> for more info.
255  
256 =cut
257  
258 sub turn_on_spatulas {
259 3 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine turn_on_spatulas: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 3 3
260 3 $self->{is_on_spatulas} = 1;
261 }
262  
263 sub turn_off_spatulas {
264 0 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine turn_off_spatulas: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 0 0
265 0 $self->{is_on_spatulas} = 0;
266 }
267  
268 sub is_on_spatulas {
269 4 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Subroutine is_on_spatulas: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 0 4 4
270 4 $self->{is_on_spatulas};
271 }
272  
273 =head1 AUTHOR
274  
275 Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >>
276  
277 =head1 BUGS
278  
279 Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
280 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
281 automatically be notified of progress on your bug as I make changes.
282  
283  
284  
285  
286 =head1 SUPPORT
287  
288 You can find documentation for this module with the perldoc command.
289  
290 perldoc Acme::FishFarm::WaterFiltration
291  
292  
293 You can also look for information at:
294  
295 =over 4
296  
297 =item * RT: CPAN's request tracker (report bugs here)
298  
299 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.>
300  
301 =item * CPAN Ratings
302  
303 L<https://cpanratings.perl.org/d/.>
304  
305 =item * Search CPAN
306  
307 L<https://metacpan.org/release/.>
308  
309 =back
310  
311  
312 =head1 ACKNOWLEDGEMENTS
313  
314 Besiyata d'shmaya
315  
316 =head1 LICENSE AND COPYRIGHT
317  
318 This software is Copyright (c) 2021 by Raphael Jong Jun Jie.
319  
320 This is free software, licensed under:
321  
322 The Artistic License 2.0 (GPL Compatible)
323  
324  
325 =cut
326  
327 3 1; # End of Acme::FishFarm::WaterFiltration
« FishFarm/Feeder.pm ↑ Summary FishFarm.pm »