Acme-FishFarm
view release on metacpan or search on metacpan
lib/Acme/FishFarm/OxygenMaintainer.pm view on Meta::CPAN
package Acme::FishFarm::OxygenMaintainer;
use 5.006;
use strict;
use warnings;
use Carp "croak";
=head1 NAME
Acme::FishFarm::OxygenMaintainer - Oxygen Maintainer for Acme::FishFarm
=head1 VERSION
Version 1.01
=cut
our $VERSION = '1.01';
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm qw(consume_oxygen reduce_precision);
use Acme::FishFarm::OxygenMaintainer;
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 );
say "Oxygen maintainer installed!\n";
while ( "fish are using up oxygen" ) {
say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L",
" (low: < ", $oxygen->DO_threshold, ")";
#say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L";
if ( $oxygen->is_low_DO ) {
say "Fish status: Suffocating";
say " !! Low oxygen level!";
say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ;
$oxygen->generate_oxygen;
} else {
say "Fish status: Happy";
}
consume_oxygen( $oxygen, rand(2.5) );
sleep(3);
say "";
}
=head1 EXPORT
None
=head1 CREATION RELATED SUBROUTINES/METHODS
=head2 install ( %options )
Installs an oxygen maintainer system.
The supported C<%options> are:
=over 4
=item current_DO
The default DO is to C<8 mg/L>.
=item DO_threshold
The default threshold is C<5 mg/L>.
If the current DO level is lower than this threshold, then your fish is lacking oxygen.
=item DO_generation_volume
This is the rate of oxygen generation.
The default value is C<0.2 mg/L per unit time>
=back
The unit C<mg/L> is just a unit, it doesn't show up if you call any of it's related getters.
=cut
sub install {
my $class = shift;
my %options = @_;
if ( not $options{current_DO} ) {
$options{current_DO} = 8;
}
if ( not $options{DO_threshold} ) {
$options{DO_threshold} = 5;
}
if ( not $options{DO_generation_volume} ) {
$options{DO_generation_volume} = 0.2;
}
$options{is_DO_low} = 0; # might be useless :)
bless \%options, "Acme::FishFarm::OxygenMaintainer";
}
( run in 1.481 second using v1.01-cache-2.11-cpan-54e63673c56 )