view release on metacpan or search on metacpan
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
<li><a href="#VERSION">VERSION</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#EXPORT">EXPORT</a></li>
<li><a href="#CREATION-RELATED-METHODS">CREATION RELATED METHODS</a>
<ul>
<li><a href="#install-options">install ( %options )</a></li>
</ul>
</li>
<li><a href="#TIMER-RELATED-SUBROUTINES-METHODS">TIMER RELATED SUBROUTINES/METHODS</a>
<ul>
<li><a href="#get_timer">get_timer</a></li>
<li><a href="#set_timer-time">set_timer ( $time )</a></li>
<li><a href="#timer_is_up">timer_is_up</a></li>
<li><a href="#time_remaining">time_remaining</a></li>
<li><a href="#tick_clock-custom_tick">tick_clock ( $custom_tick )</a></li>
</ul>
</li>
<li><a href="#FOOD-TANK-RELATED-SUBROUTINE-METHODS">FOOD TANK RELATED SUBROUTINE/METHODS</a>
<ul>
<li><a href="#food_tank_capacity">food_tank_capacity</a></li>
<li><a href="#set_food_tank_capacity-new_capacity">set_food_tank_capacity ( $new_capacity )</a></li>
<li><a href="#food_remaining">food_remaining</a></li>
</ul>
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
<h1 id="VERSION">VERSION</h1>
<p>Version 1.01</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
while ( "fish are living happilly" ) {
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish;
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <= 0 ) {
$feeder->refill; # default back to 500 cm^3
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
<h1 id="CREATION-RELATED-METHODS">CREATION RELATED METHODS</h1>
<h2 id="install-options">install ( %options )</h2>
<p>Installs an automated fish feeder.</p>
<p>The following are available for <code>%options</code>:</p>
<ul>
<li><p>timer</p>
<p>The default is <code>8</code>.</p>
<p>This is used as a threshold to identify that the time is up to feed the fish or not.</p>
<p>The clock will be set to this value for countdown.</p>
</li>
<li><p>feeding_volume</p>
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
</li>
<li><p>current_food_amount</p>
<p>The initial amount of food to be filled into the food tank. Default is max ie <code>500 cm^3</code>.</p>
</li>
</ul>
<h1 id="TIMER-RELATED-SUBROUTINES-METHODS">TIMER RELATED SUBROUTINES/METHODS</h1>
<h2 id="get_timer">get_timer</h2>
<p>Returns the timer threshold of the feeder.</p>
<h2 id="set_timer-time">set_timer ( $time )</h2>
<p>Sets the new timer threshold of the feeder.</p>
<p>Setting this timer will not affect the clock within the feeder.</p>
<h2 id="timer_is_up">timer_is_up</h2>
<p>Check if the timer is up. If timer is up, please remember to feed your fish. See <code>feed_fish</code> for more info.</p>
<h2 id="time_remaining">time_remaining</h2>
<p>Returns the time remaining to feed the fish.</p>
<p>This method might not be really useful, but anyway :)</p>
<h2 id="tick_clock-custom_tick">tick_clock ( $custom_tick )</h2>
<p><code>$custom_tick</code> is optional and the default is <code>1</code>.</p>
<p>This will cause the timer of the feeder to increase by <code>1</code> (default) or by <code>$custom_tick</code>.</p>
<h1 id="FOOD-TANK-RELATED-SUBROUTINE-METHODS">FOOD TANK RELATED SUBROUTINE/METHODS</h1>
<h2 id="food_tank_capacity">food_tank_capacity</h2>
<p>Returns the current food tank capacity.</p>
<h2 id="set_food_tank_capacity-new_capacity">set_food_tank_capacity ( $new_capacity )</h2>
<p>Set the new food tank capacity to <code>$new_capacity</code>.</p>
docs/Acme-FishFarm-Feeder-1.01.html view on Meta::CPAN
<h2 id="food_remaining">food_remaining</h2>
<p>Returns the remaining amount of food left.</p>
<h1 id="FEEDING-RELATED-SUBROUTINES-METHODS">FEEDING RELATED SUBROUTINES/METHODS</h1>
<h2 id="feed_fish-options">feed_fish ( %options )</h2>
<p>Feeds the fish.</p>
<p>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 <code>timer_is_up</code> for more info.</p>
<p><code>%options</code> supports the following key:</p>
<ul>
<li><p>verbose</p>
<p>Setting this to a true value will give output about the feeder's situation when feeding the fish.</p>
</li>
docs/items_list view on Meta::CPAN
[v] render_buzzer
[v] tests
[v] Acme::FishFarm::Feeder
[v] synopsis
[v] gist
[v] implementation
[v] CREATION
[v] install
[v] TIMER
[v] get_timer
[v] set_timer
[v] timer_is_up
[v] time_remaining
[v] tick_clock
[v] FOOD TANK
[v] food_tank_capacity
[v] set_food_tank_capacity
[v] food_remaining
[v] FEEDING
[v] feed_fish
[v] set_feeding_volume
[v] feeding_volume
docs/specifications view on Meta::CPAN
values
2.1 Acme::FishFarm::WaterLevelMaintainer
2.2 Acme::FishFarm::Feeder
2.3 Acme::FishFarm::WaterFiltration
2.4 Acme::FishFarm::WaterConditionMonitor
2.5 Acme::FishFarm::OxygenMaintainer
2.6 A few systems has some mechanism that can't work by itself and require explicit action, these include:
- Acme::FishFarm::Feeder
* timer needs to be ticked from time to time
- Acme::FishFarm::OxygenMaintainer
* oxygen needs to be generated constantly if DO is lower than threshold
- Acme::FishFarm::WaterLevelMaintainer
* water needs to be pumped constantly if water level is lower than threshold
There's really no obvious reason why this is so, it's just what and how I want the method names to be :)
3. Actual script:
3.1 Use YAML as config file, this file will be read every t seconds and the
program will react accordingly to the new data
3.2 Use lib so that the modules can be moved together with the scripts
lib/Acme/FishFarm.pm view on Meta::CPAN
Setting C<$verbose> to 1 will give more output about the empty food tank.
Take note that this process B<DOES NOT> trigger the LED and buzzer if abnormal condition is present.
Returns 1 upon success.
=cut
sub check_feeder {
my ( $feeder, $verbose ) = @_;
if ( $feeder->timer_is_up ) {
print "Timer is up, time to feed the fish!\n";
if ( $verbose) {
$feeder->feed_fish( verbose => 1 );
} else {
$feeder->feed_fish;
}
print " Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...\n";
} else {
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
=cut
our $VERSION = '1.01';
=head1 SYNOPSIS
use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
while ( "fish are living happilly" ) {
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish;
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <= 0 ) {
$feeder->refill; # default back to 500 cm^3
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
=head1 CREATION RELATED METHODS
=head2 install ( %options )
Installs an automated fish feeder.
The following are available for C<%options>:
=over 4
=item * timer
The default is C<8>.
This is used as a threshold to identify that the time is up to feed the fish or not.
The clock will be set to this value for countdown.
=item * feeding_volume
The default is C<50 cm^3>.
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
=back
=cut
sub install {
my $class = shift;
my %options = @_;
# value of 0 should not work
if ( not $options{timer} ) {
$options{timer} = 8; # this is used as a reference only
}
# when clock is a multiple of timer, then feed fish
$options{clock} = 0; # this is the actual one that will keep changing
if ( not $options{feeding_volume} ) {
$options{feeding_volume} = 50;
}
if ( not $options{food_tank_capacity} ) {
$options{food_tank_capacity} = 500;
}
if ( not $options{current_food_amount} ) {
$options{current_food_amount} = $options{food_tank_capacity};
}
$options{first_usage} = 1; # make sure the feeder doesn't say timer is up as soon as it is switched on
bless \%options, $class;
}
=head1 TIMER RELATED SUBROUTINES/METHODS
=head2 get_timer
Returns the timer threshold of the feeder.
=cut
sub get_timer {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{timer};
}
=head2 set_timer ( $time )
Sets the new timer threshold of the feeder.
Setting this timer will not affect the clock within the feeder.
=cut
sub set_timer {
ref( my $self = shift ) or croak "Please use this the OO way";
$self->{timer} = shift;
}
=head2 timer_is_up
Check if the timer is up. If timer is up, please remember to feed your fish. See C<feed_fish> for more info.
=cut
sub timer_is_up {
ref (my $self = shift) or croak "Please use this the OO way";
# skip the first round, 0 % n is always 0 and the feeder might think it's time to feed the fish as soon as it's switched on
if ( $self->{first_usage} ) {
$self->{first_usage} = 0;
return 0;
}
if ( $self->{clock} % $self->{timer} == 0 ) {
# reset clock to 0 and return true
$self->{clock} = 0; # just in case the clock runs for too long
1;
} else {
0;
}
}
=head2 time_remaining
Returns the time remaining to feed the fish.
This method might not be really useful, but anyway :)
=cut
sub time_remaining {
ref (my $self = shift) or croak "Please use this the OO way";
$self->{timer} - $self->{clock};
}
=head2 tick_clock ( $custom_tick )
C<$custom_tick> is optional and the default is C<1>.
This will cause the timer of the feeder to increase by C<1> (default) or by C<$custom_tick>.
=cut
sub tick_clock {
ref (my $self = shift) or croak "Please use this the OO way";
++$self->{clock};
}
=head1 FOOD TANK RELATED SUBROUTINE/METHODS
lib/Acme/FishFarm/Feeder.pm view on Meta::CPAN
$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
scripts/feeder.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
say "Feeder installed and switched on!";
say "";
#while (1) {
for (0..20){
if ( $feeder->timer_is_up ) {
say "\nTimer is up, time to feed the fish!";
say "Feeding ", $feeder->feeding_volume, " cm^3 of fish food to the fish...";
$feeder->feed_fish ( verbose => 1 );
say $feeder->food_remaining, " cm^3 of fish food remaining in the tank.\n";
}
if ( $feeder->food_remaining <=0 ) {
$feeder->refill; # default back to 500 cm^3
scripts/feeder_2.pl view on Meta::CPAN
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Acme::FishFarm ":all";
use Acme::FishFarm::Feeder;
my $feeder = Acme::FishFarm::Feeder->install( timer => 3, feeding_volume => 150 );
while ( "fish are living in the water..." ) {
check_feeder( $feeder, verbose => 1 );
sleep 2;
say "";
}
# besiyata d'shmaya
t/04-feeder.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Output;
BEGIN {
use_ok( "Acme::FishFarm::Feeder" ) || BAIL_OUT;
}
ok( my $feeder_default = Acme::FishFarm::Feeder->install(), "Feeder installed" ); # timer 1 hour, 50 cm^3 fish food
#print $feeder_default, "\n";
is( ref($feeder_default), "Acme::FishFarm::Feeder", "Correct class name");
ok( my $feeder_h5_v15 = Acme::FishFarm::Feeder->install( timer => 5, feeding_volume => 15 ), "Feeder installed" );
is( ref($feeder_h5_v15), "Acme::FishFarm::Feeder", "Correct class name");
ok( my $feeder_h3 = Acme::FishFarm::Feeder->install( timer => 3 ), "Feeder installed" );
is( ref($feeder_h3), "Acme::FishFarm::Feeder", "Correct class name");
ok( my $feeder_v45 = Acme::FishFarm::Feeder->install( feeding_volume => 45 ), "Feeder installed" );
is( ref($feeder_v45), "Acme::FishFarm::Feeder", "Correct class name");
# this shuold get back the default values
ok( my $feeder_all_0 = Acme::FishFarm::Feeder->install( timer =>0, feeding_volume => 0 ), "Feeder installed" );
is( ref($feeder_all_0), "Acme::FishFarm::Feeder", "Correct class name");
is( $feeder_all_0->get_timer(), 8, "Zero hours defaults to 8 hours");
is( $feeder_all_0->feeding_volume(), 50, "Zero cm^3 defaults to 50 cm^3");
is( $feeder_default->get_timer(), 8, "Correct default timer" );
# tick_clock part will go into a loop in the actual program
isnt( $feeder_default->timer_is_up, 1, "Not feeding fish as soon as feeder is switched on" );
ok( $feeder_default->tick_clock(), "Clock ticks once ($_)" ) for (0..3);
is( $feeder_default->time_remaining(), 4, "Correct time remaining" );
isnt( $feeder_default->timer_is_up(), 1, "Time isn't up yet'" );
ok( $feeder_default->tick_clock(), "Clock ticks once ($_)" ) for (4..7);
is( $feeder_default->timer_is_up(), 1, "Time to feed the fish'" );
#print $feeder_default->tick_clock() . "\n";
#print $feeder_default->tick_clock() . "\n";
#print $feeder_default->tick_clock() . "\n";
# test food tank
is($feeder_default->food_remaining(), 500, "Correct default food level");
is($feeder_default->feeding_volume(), 50, "Correct default feeding volume");
$feeder_default->set_feeding_volume(25);