| 1 | package Acme::FishFarm::OxygenMaintainer; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use Carp "croak"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Acme::FishFarm::OxygenMaintainer - Oxygen Maintainer for Acme::FishFarm | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 1.01 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 4 | our $VERSION = '1.01'; | |||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use 5.010; | ||||||||||
| 24 | |||||||||||
| 25 | use Acme::FishFarm qw(consume_oxygen reduce_precision); | ||||||||||
| 26 | use Acme::FishFarm::OxygenMaintainer; | ||||||||||
| 27 | |||||||||||
| 28 | my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 ); | ||||||||||
| 29 | say "Oxygen maintainer installed!\n"; | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | while ( "fish are using up oxygen" ) { | ||||||||||
| 33 | say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L", | ||||||||||
| 34 | " (low: < ", $oxygen->DO_threshold, ")"; | ||||||||||
| 35 | #say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L"; | ||||||||||
| 36 | |||||||||||
| 37 | if ( $oxygen->is_low_DO ) { | ||||||||||
| 38 | say "Fish status: Suffocating"; | ||||||||||
| 39 | say " !! Low oxygen level!"; | ||||||||||
| 40 | say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ; | ||||||||||
| 41 | $oxygen->generate_oxygen; | ||||||||||
| 42 | } else { | ||||||||||
| 43 | say "Fish status: Happy"; | ||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | consume_oxygen( $oxygen, rand(2.5) ); | ||||||||||
| 47 | |||||||||||
| 48 | sleep(3); | ||||||||||
| 49 | say ""; | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | =head1 EXPORT | ||||||||||
| 53 | |||||||||||
| 54 | None | ||||||||||
| 55 | |||||||||||
| 56 | =head1 CREATION RELATED SUBROUTINES/METHODS | ||||||||||
| 57 | |||||||||||
| 58 | =head2 install ( %options ) | ||||||||||
| 59 | |||||||||||
| 60 | Installs an oxygen maintainer system. | ||||||||||
| 61 | |||||||||||
| 62 | The supported C<%options> are: | ||||||||||
| 63 | |||||||||||
| 64 | =over 4 | ||||||||||
| 65 | |||||||||||
| 66 | =item current_DO | ||||||||||
| 67 | |||||||||||
| 68 | The default DO is to C<8 mg/L>. | ||||||||||
| 69 | |||||||||||
| 70 | =item DO_threshold | ||||||||||
| 71 | |||||||||||
| 72 | The default threshold is C<5 mg/L>. | ||||||||||
| 73 | |||||||||||
| 74 | If the current DO level is lower than this threshold, then your fish is lacking oxygen. | ||||||||||
| 75 | |||||||||||
| 76 | =item DO_generation_volume | ||||||||||
| 77 | |||||||||||
| 78 | This is the rate of oxygen generation. | ||||||||||
| 79 | |||||||||||
| 80 | The default value is C<0.2 mg/L per unit time> | ||||||||||
| 81 | |||||||||||
| 82 | =back | ||||||||||
| 83 | |||||||||||
| 84 | The unit C<mg/L> is just a unit, it doesn't show up if you call any of it's related getters. | ||||||||||
| 85 | |||||||||||
| 86 | =cut | ||||||||||
| 87 | |||||||||||
| 88 | 5 | ▶ | sub install { | ||||||||
|
Subroutine
install: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 89 | 5 | my $class = shift; | |||||||||
| 90 | 5 | my %options = @_; | |||||||||
| 91 | |||||||||||
| 92 | 5 | ▶ | if ( not $options{current_DO} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 2 | $options{current_DO} = 8; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 5 | ▶ | if ( not $options{DO_threshold} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 4 | $options{DO_threshold} = 5; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 5 | ▶ | if ( not $options{DO_generation_volume} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 5 | $options{DO_generation_volume} = 0.2; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 5 | $options{is_DO_low} = 0; # might be useless :) | |||||||||
| 105 | |||||||||||
| 106 | 5 | bless \%options, "Acme::FishFarm::OxygenMaintainer"; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | |||||||||||
| 110 | =head1 DISSOLVED OXYGEN SENSOR RELATED METHODS | ||||||||||
| 111 | |||||||||||
| 112 | =head2 current_DO ( $new_DO ) | ||||||||||
| 113 | |||||||||||
| 114 | Sets / returns the current DO level of the water. | ||||||||||
| 115 | |||||||||||
| 116 | C<$new_DO> is optional. If present, the current DO will be set to C<$new_DO>. Otherwise, returns the current DO reading. | ||||||||||
| 117 | |||||||||||
| 118 | =cut | ||||||||||
| 119 | |||||||||||
| 120 | 13 | ▶ | sub current_DO { | ||||||||
|
Subroutine
current_DO: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 121 | 13 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | 13 | ▶ | if ( @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 6 | $self->{current_DO} = shift; | |||||||||
| 124 | } else { | ||||||||||
| 125 | 7 | $self->{current_DO}; | |||||||||
| 126 | } | ||||||||||
| 127 | |||||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | =head2 DO_threshold | ||||||||||
| 131 | |||||||||||
| 132 | Returns the DO threshold. | ||||||||||
| 133 | |||||||||||
| 134 | =cut | ||||||||||
| 135 | |||||||||||
| 136 | 5 | ▶ | sub DO_threshold { | ||||||||
|
Subroutine
DO_threshold: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 137 | 5 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 5 | $self->{DO_threshold}; | |||||||||
| 139 | } | ||||||||||
| 140 | |||||||||||
| 141 | =head2 set_DO_threshold ( $new_DO_threshold ) | ||||||||||
| 142 | |||||||||||
| 143 | Sets the DO threshold. | ||||||||||
| 144 | |||||||||||
| 145 | =cut | ||||||||||
| 146 | |||||||||||
| 147 | 2 | ▶ | sub set_DO_threshold { | ||||||||
|
Subroutine
set_DO_threshold: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 148 | 2 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 2 | my $new_do_threshold = shift; | |||||||||
| 150 | 2 | $self->{DO_threshold} = $new_do_threshold; | |||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | =head2 is_low_DO | ||||||||||
| 154 | |||||||||||
| 155 | Returns C<1> if the DO level is less than the threshold value. Otherwise, returns C<0>. | ||||||||||
| 156 | |||||||||||
| 157 | =cut | ||||||||||
| 158 | |||||||||||
| 159 | 10 | ▶ | sub is_low_DO { | ||||||||
|
Subroutine
is_low_DO: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 160 | 10 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 161 | 10 | ▶ | if ( $self->{current_DO} < $self->{DO_threshold} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 162 | 5 | return 1; | |||||||||
| 163 | } else { | ||||||||||
| 164 | 5 | return 0; | |||||||||
| 165 | } | ||||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | |||||||||||
| 169 | =head1 OXYGEN GENERATING RELATED METHODS | ||||||||||
| 170 | |||||||||||
| 171 | =head2 oxygen_generation_volume | ||||||||||
| 172 | |||||||||||
| 173 | Returns the oxygen generation rate. | ||||||||||
| 174 | |||||||||||
| 175 | =cut | ||||||||||
| 176 | |||||||||||
| 177 | 3 | ▶ | sub oxygen_generation_volume { | ||||||||
|
Subroutine
oxygen_generation_volume: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 178 | 3 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 3 | $self->{DO_generation_volume}; | |||||||||
| 180 | } | ||||||||||
| 181 | |||||||||||
| 182 | =head2 set_oxygen_generation_volume ( $new_rate ) | ||||||||||
| 183 | |||||||||||
| 184 | Sets the new oxygen generation rate to C<$new_rate>. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||
| 187 | |||||||||||
| 188 | 1 | ▶ | sub set_oxygen_generation_volume { | ||||||||
|
Subroutine
set_oxygen_generation_volume: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 189 | 1 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 190 | 1 | $self->{DO_generation_volume} = shift; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | =head2 generate_oxygen | ||||||||||
| 194 | |||||||||||
| 195 | Pumps oxygen into the water based on the diffusion rate. The current DO value will increase every time this action is invoked. | ||||||||||
| 196 | |||||||||||
| 197 | Take note that this will generate oxygen no matter what. Make sure you check the DO content before pumping oxygen into your tank. See C<is_low_DO> method above for more info. | ||||||||||
| 198 | |||||||||||
| 199 | =cut | ||||||||||
| 200 | |||||||||||
| 201 | 2 | ▶ | sub generate_oxygen { | ||||||||
|
Subroutine
generate_oxygen: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||
| 202 | 2 | ▶ | ref( my $self = shift ) or croak "Please use this the OO way"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 203 | 2 | $self->{current_DO} += $self->{DO_generation_volume}; | |||||||||
| 204 | } | ||||||||||
| 205 | |||||||||||
| 206 | =head1 AUTHOR | ||||||||||
| 207 | |||||||||||
| 208 | Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >> | ||||||||||
| 209 | |||||||||||
| 210 | =head1 BUGS | ||||||||||
| 211 | |||||||||||
| 212 | Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through | ||||||||||
| 213 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll | ||||||||||
| 214 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 215 | |||||||||||
| 216 | |||||||||||
| 217 | |||||||||||
| 218 | |||||||||||
| 219 | =head1 SUPPORT | ||||||||||
| 220 | |||||||||||
| 221 | You can find documentation for this module with the perldoc command. | ||||||||||
| 222 | |||||||||||
| 223 | perldoc Acme::FishFarm::OxygenMaintainer | ||||||||||
| 224 | |||||||||||
| 225 | |||||||||||
| 226 | You can also look for information at: | ||||||||||
| 227 | |||||||||||
| 228 | =over 4 | ||||||||||
| 229 | |||||||||||
| 230 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||
| 231 | |||||||||||
| 232 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||||||||||
| 233 | |||||||||||
| 234 | =item * CPAN Ratings | ||||||||||
| 235 | |||||||||||
| 236 | L<https://cpanratings.perl.org/d/.> | ||||||||||
| 237 | |||||||||||
| 238 | =item * Search CPAN | ||||||||||
| 239 | |||||||||||
| 240 | L<https://metacpan.org/release/.> | ||||||||||
| 241 | |||||||||||
| 242 | =back | ||||||||||
| 243 | |||||||||||
| 244 | |||||||||||
| 245 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 246 | |||||||||||
| 247 | Besiyata d'shmaya | ||||||||||
| 248 | |||||||||||
| 249 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 250 | |||||||||||
| 251 | This software is Copyright (c) 2021 by Raphael Jong Jun Jie. | ||||||||||
| 252 | |||||||||||
| 253 | This is free software, licensed under: | ||||||||||
| 254 | |||||||||||
| 255 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 256 | |||||||||||
| 257 | |||||||||||
| 258 | =cut | ||||||||||
| 259 | |||||||||||
| 260 | 4 | 1; # End of Acme::FishFarm::OxygenMaintainer | |||||||||