File Coverage

blib/lib/Acme/FishFarm/WaterFiltration.pm
Criterion Covered Total %
statement 61 64 95.3
branch 28 42 66.6
condition n/a
subroutine 17 18 94.4
pod 13 13 100.0
total 119 137 86.8


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