Acme-FishFarm
view release on metacpan or search on metacpan
lib/Acme/FishFarm/WaterFiltration.pm view on Meta::CPAN
=head2 is_filter_layer_dirty
Synonym for C<is_cylinder_dirty>. See next method.
=head2 is_cylinder_dirty
Returns C<1> if the filtering cylinder is dirty ie current waste count hits the waste count threshold. Returns C<0> otherwise.
Remember to clean your cylinder ie. filter layer as soon as possible if it is dirty.
=cut
sub is_filter_layer_dirty {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->is_cylinder_dirty;
}
sub is_cylinder_dirty {
ref( my $self = shift ) or croak "Please use this the OO way";
if ( $self->{current_waste_count} >= $self->{waste_threshold} ) {
return 1;
} else {
return 0;
}
}
=head1 CLEANING RELATED SUBROUTINES/METHODS
=head2 clean_filter_layer
Synonym for C<is_cylinder_dirty>. See next method.
=cut
sub clean_filter_layer {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->clean_cylinder(@_);
}
=head2 clean_cylinder ( $reduce_waste_by )
Cleans the filter layer in the cylinder.
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>.
If C<$reduce_waste_by> is a negative value, it will be turned into a positive value with the same magnitude.
Make sure that you turn on the spatulas, if not this process will not do anything :) See C<turn_on_spatulas> below.
=cut
sub clean_cylinder {
no warnings "numeric";
ref( my $self = shift ) or croak "Please use this the OO way";
my $reduce_waste_by;
if (@_) {
my $reduce = shift;
if ( $reduce < 0 ) {
$reduce_waste_by = abs($reduce);
# futhre error checking is done in Acme::FishFarm::check_water_filter
} else {
$reduce_waste_by = $reduce;
}
} else {
$reduce_waste_by = 0;
}
if ( $self->{is_on_spatulas} ) {
if ( $reduce_waste_by ) {
#reduce based on user input
if ( $self->{current_waste_count} > $reduce_waste_by ) {
$self->{current_waste_count} -= $reduce_waste_by;
} else {
# $reduce_waste_by not specified
$self->{current_waste_count} = 0;
}
} else {
$self->{current_waste_count} = 0;
}
} else {
return;
}
}
=head2 turn_on_spatulas
Activates the cleaning mechanism ie the spatulas :)
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 :)
=head2 turn_off_spatulas
Deactivates the cleaning mechanism ie the spatulas :)
=head2 is_on_spatulas
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.
=cut
sub turn_on_spatulas {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{is_on_spatulas} = 1;
}
sub turn_off_spatulas {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{is_on_spatulas} = 0;
}
sub is_on_spatulas {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{is_on_spatulas};
}
=head1 AUTHOR
Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >>
( run in 1.429 second using v1.01-cache-2.11-cpan-39bf76dae61 )