Acme-FishFarm
view release on metacpan or search on metacpan
lib/Acme/FishFarm/WaterLevelMaintainer.pm view on Meta::CPAN
} else {
print " Water level is still normal.\n";
}
sleep(1);
say "";
}
=head1 EXPORT
None
=head1 CREATION RELATED MEHODS
=head2 install ( %options )
Installs a water level maintainer system. This system only pumps water in if the water level is lower than the threshold value.
The supported C<%options> are:
=over 4
=item current_water_level
The default water level is to C<5 unit>.
=item low_water_level_threshold
The default threshold is C<2 unit>.
If the current water level is lower than this threshold, then you need to pump water into the tank.
=item increase_water_level_by
This is the height of the water level to increase when the water is pumped in.
The default value is C<0.5 unit>.
=back
=cut
sub install {
my $class = shift;
my %options = @_;
if ( not $options{current_water_level} ) {
$options{current_water_level} = 5;
}
if ( not $options{low_water_level_threshold} ) {
$options{low_water_level_threshold} = 2;
}
if ( not $options{increase_water_level_by} ) {
$options{increase_water_level_by} = 0.5;
}
$options{is_low_water_level} = 0; # might be useless :)
bless \%options, "Acme::FishFarm::WaterLevelMaintainer";
}
=head1 WATER LEVEL DETECTION RELATED METHODS
=head2 current_water_level ( $new_water_level )
Sets / returns the current water level of the water.
C<$new_water_level> is optional. If present, the current water level will be set to C<$new_water_level>. Otherwise, returns the current water level (depth).
=cut
sub current_water_level {
ref( my $self = shift ) or croak "Please use this the OO way";
if ( @_ ) {
$self->{current_water_level} = shift;
} else {
$self->{current_water_level};
}
}
=head2 low_water_level_threshold
Returns the low water level threshold.
=cut
sub low_water_level_threshold {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{low_water_level_threshold};
}
=head2 set_low_water_level_threshold ( $new_threshold )
Sets the low water level threshold.
=cut
sub set_low_water_level_threshold {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{low_water_level_threshold} = shift;
}
=head2 is_low_water_level
Returns C<1> if the DO level is less than the threshold value. Otherwise, returns C<0>.
=cut
sub is_low_water_level {
ref( my $self = shift ) or croak "Please use this the OO way";
if ( $self->{current_water_level} < $self->{low_water_level_threshold} ) {
return 1;
} else {
return 0;
}
}
=head1 PUMPS RELATED METHODS
( run in 1.249 second using v1.01-cache-2.11-cpan-d8267643d1d )