| 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.01 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 3 | 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<here|https://www.filternox.com/filters/spt-wbv-mr/> | ||||||||||
| 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 | 3 | ▶ | sub install { | ||||||||
|
Subroutine
install: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 100 | 3 | my $class = shift; | |||||||||
| 101 | 3 | my %options = @_; | |||||||||
| 102 | |||||||||||
| 103 | 3 | ▶ | if ( not $options{current_waste_count} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 2 | $options{current_waste_count} = 0; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 3 | ▶ | if ( not $options{waste_threshold} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 2 | $options{waste_threshold} = 75; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | 3 | $options{is_on_spatulas} = 0; | |||||||||
| 112 | 3 | $options{reduce_waste_count_by} = 10; | |||||||||
| 113 | |||||||||||
| 114 | 3 | 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 | 14 | ▶ | sub current_waste_count { | ||||||||
|
Subroutine
current_waste_count: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 129 | 14 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | |||||||||||
| 131 | 14 | ▶ | if ( @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | 6 | $self->{current_waste_count} = shift; | |||||||||
| 133 | } else { | ||||||||||
| 134 | 8 | $self->{current_waste_count}; | |||||||||
| 135 | } | ||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | =head2 waste_count_threshold | ||||||||||
| 139 | |||||||||||
| 140 | Returns the waste count threshold. | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | 4 | ▶ | sub waste_count_threshold { | ||||||||
|
Subroutine
waste_count_threshold: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 145 | 4 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 4 | $self->{waste_threshold}; | |||||||||
| 147 | } | ||||||||||
| 148 | |||||||||||
| 149 | =head2 set_waste_count_threshold | ||||||||||
| 150 | |||||||||||
| 151 | Sets the waste count threshold. | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | 1 | ▶ | sub set_waste_count_threshold { | ||||||||
|
Subroutine
set_waste_count_threshold: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 156 | 1 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 1 | $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 | 4 | ▶ | sub reduce_waste_count_by { | ||||||||
|
Subroutine
reduce_waste_count_by: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 167 | 4 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 168 | 4 | $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 | 1 | ▶ | sub set_waste_count_to_reduce { | ||||||||
|
Subroutine
set_waste_count_to_reduce: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 178 | 1 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 1 | $self->{reduce_waste_count_by} = shift; | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | =head2 is_filter_layer_dirty | ||||||||||
| 183 | |||||||||||
| 184 | Synonym for C<is_cylinder_dirty>. 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 | 3 | ▶ | sub is_filter_layer_dirty { | ||||||||
|
Subroutine
is_filter_layer_dirty: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 195 | 3 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | 3 | $self->is_cylinder_dirty; | |||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | 6 | ▶ | sub is_cylinder_dirty { | ||||||||
|
Subroutine
is_cylinder_dirty: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 200 | 6 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 201 | 6 | ▶ | if ( $self->{current_waste_count} >= $self->{waste_threshold} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 202 | 4 | return 1; | |||||||||
| 203 | } else { | ||||||||||
| 204 | 2 | return 0; | |||||||||
| 205 | } | ||||||||||
| 206 | } | ||||||||||
| 207 | |||||||||||
| 208 | =head1 CLEANING RELATED SUBROUTINES/METHODS | ||||||||||
| 209 | |||||||||||
| 210 | =head2 clean_filter_layer | ||||||||||
| 211 | |||||||||||
| 212 | Synonym for C<is_cylinder_dirty>. See next method. | ||||||||||
| 213 | |||||||||||
| 214 | =cut | ||||||||||
| 215 | |||||||||||
| 216 | 1 | ▶ | sub clean_filter_layer { | ||||||||
|
Subroutine
clean_filter_layer: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 217 | 1 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 218 | 1 | $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<turn_on_spatulas> below. | ||||||||||
| 230 | |||||||||||
| 231 | =cut | ||||||||||
| 232 | |||||||||||
| 233 | 5 | ▶ | sub clean_cylinder { | ||||||||
|
Subroutine
clean_cylinder: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||
| 234 | 3 | ▶ | no warnings "numeric"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 235 | 5 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 236 | |||||||||||
| 237 | 5 | my $reduce_waste_by; | |||||||||
| 238 | 5 | ▶ | if (@_) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 239 | 2 | my $reduce = shift; | |||||||||
| 240 | 2 | ▶ | if ( $reduce < 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 241 | 1 | $reduce_waste_by = abs($reduce); | |||||||||
| 242 | # futhre error checking is done in Acme::FishFarm::check_water_filter | ||||||||||
| 243 | } else { | ||||||||||
| 244 | 1 | $reduce_waste_by = $reduce; | |||||||||
| 245 | } | ||||||||||
| 246 | } else { | ||||||||||
| 247 | 3 | $reduce_waste_by = 0; | |||||||||
| 248 | } | ||||||||||
| 249 | |||||||||||
| 250 | 5 | ▶ | if ( $self->{is_on_spatulas} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 251 | |||||||||||
| 252 | 4 | ▶ | if ( $reduce_waste_by ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 253 | #reduce based on user input | ||||||||||
| 254 | 2 | ▶ | if ( $self->{current_waste_count} > $reduce_waste_by ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 255 | 2 | $self->{current_waste_count} -= $reduce_waste_by; | |||||||||
| 256 | } else { | ||||||||||
| 257 | # $reduce_waste_by not specified | ||||||||||
| 258 | 0 | $self->{current_waste_count} = 0; | |||||||||
| 259 | } | ||||||||||
| 260 | } else { | ||||||||||
| 261 | 2 | $self->{current_waste_count} = 0; | |||||||||
| 262 | } | ||||||||||
| 263 | |||||||||||
| 264 | } else { | ||||||||||
| 265 | 1 | 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<clean_cylinder> 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<clean_cylinder> method above for more info. | ||||||||||
| 282 | |||||||||||
| 283 | =cut | ||||||||||
| 284 | |||||||||||
| 285 | 3 | ▶ | sub turn_on_spatulas { | ||||||||
|
Subroutine
turn_on_spatulas: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 286 | 3 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 287 | 3 | $self->{is_on_spatulas} = 1; | |||||||||
| 288 | } | ||||||||||
| 289 | |||||||||||
| 290 | 0 | ▶ | sub turn_off_spatulas { | ||||||||
|
Subroutine
turn_off_spatulas: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 291 | 0 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 292 | 0 | $self->{is_on_spatulas} = 0; | |||||||||
| 293 | } | ||||||||||
| 294 | |||||||||||
| 295 | 4 | ▶ | sub is_on_spatulas { | ||||||||
|
Subroutine
is_on_spatulas: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 296 | 4 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 297 | 4 | $self->{is_on_spatulas}; | |||||||||
| 298 | } | ||||||||||
| 299 | |||||||||||
| 300 | =head1 AUTHOR | ||||||||||
| 301 | |||||||||||
| 302 | Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >> | ||||||||||
| 303 | |||||||||||
| 304 | =head1 BUGS | ||||||||||
| 305 | |||||||||||
| 306 | Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through | ||||||||||
| 307 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. 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<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||||||||||
| 327 | |||||||||||
| 328 | =item * CPAN Ratings | ||||||||||
| 329 | |||||||||||
| 330 | L<https://cpanratings.perl.org/d/.> | ||||||||||
| 331 | |||||||||||
| 332 | =item * Search CPAN | ||||||||||
| 333 | |||||||||||
| 334 | L<https://metacpan.org/release/.> | ||||||||||
| 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 | 3 | 1; # End of Acme::FishFarm::WaterFiltration | |||||||||