Acme-FishFarm
view release on metacpan or search on metacpan
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
=cut
sub set_food_tank_capacity {
no warnings "numeric";
ref (my $self = shift) or croak "Please use this the OO way";
my $new_capacity = int (shift) || return;
$self->{food_tank_capacity} = $new_capacity;
}
=head2 food_remaining
Returns the remaining amount of food left.
=cut
sub food_remaining {
ref (my $self = shift) or croak "Please use this the OO way";
$self->{current_food_amount};
}
=head1 FEEDING RELATED SUBROUTINES/METHODS
=head2 feed_fish ( %options )
Feeds the fish.
Take note that this will feed the fish no matter what. So it's up to you to make sure that you check if the
feeder timer is really up or not before calling this method. See C<timer_is_up> for more info.
C<%options> supports the following key:
=over 4
=item * verbose
Setting this to a true value will give output about the feeder's situation when feeding the fish.
=back
=cut
sub feed_fish {
ref (my $self = shift) or croak "Please use this the OO way";
my %options = @_;
if ( $self->{current_food_amount} - $self->{feeding_volume} <= 0 ) {
if ( $options{verbose} ) {
print "Your feeder has run out of food, please refill as soon as possible.\n";
print "Only managed to feed $self->{current_food_amount} cm^3 of food to the fish.\n";
}
$self->{current_food_amount} = 0;
} else {
$self->{current_food_amount} = $self->{current_food_amount} - $self->{feeding_volume};
}
}
=head2 set_feeding_volume ( $volume )
Sets the fish food feeding volume.
C<$volume> must be a positive number. No error checking is done for this yet.
=cut
sub set_feeding_volume {
ref (my $self = shift) or croak "Please use this the OO way";
my $volume = shift or croak "Please specify feeding volume";
$self->{feeding_volume} = $volume;
}
=head2 feeding_volume
Returns the amount of food to feed the fish each time the C<feed_fish> method is called.
=cut
sub feeding_volume {
ref (my $self = shift) or croak "Please use this the OO way";
$self->{feeding_volume};
}
=head2 refill ( $volume )
Refills the fish food tank B<TO> C<$volume>.
If C<$volume> is not specified, the food tank will be filled to max.
If C<$volume> is a strange value, it will be ignored and filled to max.
=cut
sub refill {
no warnings "numeric";
ref (my $self = shift) or croak "Please use this the OO way";
my $volume = shift || $self->{food_tank_capacity};
return if not int($volume);
if ( $volume > $self->{food_tank_capacity} ) {
$self->{current_food_amount} = $self->{food_tank_capacity};
} else {
$self->{current_food_amount} = $volume;
}
}
=head1 AUTHOR
Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
( run in 0.642 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )