Acme-FishFarm

 view release on metacpan or  search on metacpan

lib/Acme/FishFarm/OxygenMaintainer.pm  view on Meta::CPAN

        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";
}


=head1 DISSOLVED OXYGEN SENSOR RELATED METHODS

=head2 current_DO ( $new_DO )

Sets / returns the current DO level of the water.

C<$new_DO> is optional. If present, the current DO will be set to C<$new_DO>. Otherwise, returns the current DO reading.

=cut

sub current_DO {
    ref( my $self = shift ) or croak "Please use this the OO way";
    if ( @_ ) {
        $self->{current_DO} = shift;
    } else {
        $self->{current_DO};
    }
    
}

=head2 DO_threshold

Returns the DO threshold.

=cut

sub DO_threshold {
    ref( my $self = shift ) or croak "Please use this the OO way";
    $self->{DO_threshold};
}

=head2 set_DO_threshold ( $new_DO_threshold )

Sets the DO threshold.

=cut

sub set_DO_threshold {
    ref( my $self = shift ) or croak "Please use this the OO way";
    my $new_do_threshold = shift;
    $self->{DO_threshold} = $new_do_threshold;
}

=head2 is_low_DO

Returns C<1> if the DO level is less than the threshold value. Otherwise, returns C<0>.

=cut

sub is_low_DO {
    ref( my $self = shift ) or croak "Please use this the OO way";
    if ( $self->{current_DO} < $self->{DO_threshold} ) {
        return 1;
    } else {
        return 0;
    }
}



( run in 3.470 seconds using v1.01-cache-2.11-cpan-804bf51f3ce )