Acme-FishFarm

 view release on metacpan or  search on metacpan

docs/Acme-FishFarm-1.01.html  view on Meta::CPAN

<h2 id="consume_oxygen-oxygen_maintainer-consumed_oxygen">consume_oxygen ( $oxygen_maintainer, $consumed_oxygen )</h2>

<p>This will cause the oxygen level (DO level) of the <code>Acme::FishFarm::OxygenMaintainer</code> to reduce by <code>$consumed_oxygen mg/L</code></p>

<p>Returns 1 upon success.</p>

<h2 id="check_DO-oxygen_maintainer-current_DO_reading">check_DO ( $oxygen_maintainer, $current_DO_reading )</h2>

<p>This checks and outputs the condition of the current DO level.</p>

<p>Take note that this process will trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_pH-water_monitor-current_ph_reading">check_pH ( $water_monitor, $current_ph_reading )</h2>

<p>This checks and outputs the condition of the current pH value.</p>

<p>Take note that this process will trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_temperature-water_monitor-current_temperature_reading">check_temperature ( $water_monitor, $current_temperature_reading )</h2>

<p>This checks and outputs the condition of the current temperature.</p>

<p>Take note that this process will trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_turbidity-water_monitor-current_turbidity_reading">check_turbidity ( $water_monitor, $current_turbidity_reading )</h2>

<p>This checks and outputs the condition of the current temperature.</p>

<p>Take note that this process will trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_water_filter-water_filter-current_waste_count-reduce_waste_by">check_water_filter ( $water_filter, $current_waste_count, $reduce_waste_by )</h2>

<p>This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder.</p>

<p>Take note that this process <b>DOES NOT</b> trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_water_level-water_level_maintainer-current_water_level">check_water_level ( $water_level_maintainer, $current_water_level )</h2>

<p>This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder.</p>

<p>Take note that this process <b>DOES NOT</b> trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="check_feeder-feeder-verbose">check_feeder ( $feeder, $verbose )</h2>

<p>This checks, performs necessary actions and outputs the condition of the feeder. Each call will tick the clock inside the feeder. See <code>Acme::FishFarm::Feeder</code> for more info.</p>

<p>If the food tank is empty, it will be filled to the default. So if you want to fill a different amount, please set the amount before hand. See <code>Acme::FishFarm::Feeder</code>.</p>

<p>Setting <code>$verbose</code> to 1 will give more output about the empty food tank.</p>

<p>Take note that this process <b>DOES NOT</b> trigger the LED and buzzer if abnormal condition is present.</p>

<p>Returns 1 upon success.</p>

<h2 id="render_leds-water_monitor">render_leds ( $water_monitor )</h2>

<p>Outputs which LEDs are lighted up. Returns 1 upon success.</p>

<p>Currently this subroutine only shows the LEDs present in the <code>Acme::FishFarm::WaterConditionMonitor</code> object. See that module for more details about the available LEDs.</p>

<p>More LEDs will be available in the future.</p>

docs/Acme-FishFarm-WaterFiltration-1.01.html  view on Meta::CPAN

<p>Sets the waste treshold.</p>

<p>This is the maximum limit of waste in the cylinder. When this count is hit, it will turn on the cleaners / spatulas or whatever it&#39;s called :).</p>

</dd>
<dt id="reduce_waste_count_by">reduce_waste_count_by</dt>
<dd>

<p>Default is <code>10</code>.</p>

<p>The amount of waste to remove from the cylinder / filter each time the cleaning process is called.</p>

</dd>
</dl>

<h1 id="WASTE-LEVEL-DETECTING-SUBROUTINES-METHODS">WASTE LEVEL DETECTING SUBROUTINES/METHODS</h1>

<h2 id="current_waste_count-new_waste_count">current_waste_count ( $new_waste_count )</h2>

<p>Sets / returns the current waste count inside the cylinder.</p>

docs/Acme-FishFarm-WaterFiltration-1.01.html  view on Meta::CPAN

<h2 id="waste_count_threshold">waste_count_threshold</h2>

<p>Returns the waste count threshold.</p>

<h2 id="set_waste_count_threshold">set_waste_count_threshold</h2>

<p>Sets the waste count threshold.</p>

<h2 id="reduce_waste_count_by1">reduce_waste_count_by</h2>

<p>Returns the amount of waste to be reduce each time the cleaning process is called.</p>

<h2 id="set_waste_count_to_reduce-new_count">set_waste_count_to_reduce ( $new_count )</h2>

<p>Sets the waste count reduction value to <code>$new_count</code>.</p>

<h2 id="is_filter_layer_dirty">is_filter_layer_dirty</h2>

<p>Synonym for <code>is_cylinder_dirty</code>. See next method.</p>

<h2 id="is_cylinder_dirty">is_cylinder_dirty</h2>

docs/Acme-FishFarm-WaterFiltration-1.01.html  view on Meta::CPAN

<p>Synonym for <code>is_cylinder_dirty</code>. See next method.</p>

<h2 id="clean_cylinder-reduce_waste_by">clean_cylinder ( $reduce_waste_by )</h2>

<p>Cleans the filter layer in the cylinder.</p>

<p><code>$reduce_waste_by</code> 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 <code>0</code>.</p>

<p>If <code>$reduce_waste_by</code> is a negative value, it will be turned into a positive value with the same magnitude.</p>

<p>Make sure that you turn on the spatulas, if not this process will not do anything :) See <code>turn_on_spatulas</code> below.</p>

<h2 id="turn_on_spatulas">turn_on_spatulas</h2>

<p>Activates the cleaning mechanism ie the spatulas :)</p>

<p>Take note that turning on the spatulas does not clean the cylinder. You need to do it explicitly. See <code>clean_cylinder</code> method above for more info :)</p>

<h2 id="turn_off_spatulas">turn_off_spatulas</h2>

<p>Deactivates the cleaning mechanism ie the spatulas :)</p>

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

    print "$consumed_oxygen mg/L of oxygen consumed...\n";
    my $o2_remaining = $o2_maintainer->current_DO - $consumed_oxygen;
    $o2_maintainer->current_DO( $o2_remaining );
    1;
}

=head2 check_DO ( $oxygen_maintainer, $current_DO_reading )

This checks and outputs the condition of the current DO level.

Take note that this process will trigger the LED and buzzer if abnormal condition is present.

Returns 1 upon success.
=cut

sub check_DO {
    my ( $oxygen, $current_reading ) = @_;
    my $DO_threshold = $oxygen->DO_threshold;

    $oxygen->current_DO( $current_reading );
    $oxygen->is_low_DO;

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

    } else {
        print "  Oxygen level is normal.\n";
    }
    1;
}

=head2 check_pH ( $water_monitor, $current_ph_reading )

This checks and outputs the condition of the current pH value.

Take note that this process will trigger the LED and buzzer if abnormal condition is present.

Returns 1 upon success.

=cut

sub check_pH {
    my ( $water_monitor, $current_reading ) = @_;
    my $ph_range = $water_monitor->ph_threshold;
    
    $water_monitor->current_ph( $current_reading );

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

    } else {
        print "  pH is normal.\n";
    }
    1;
}

=head2 check_temperature ( $water_monitor, $current_temperature_reading )

This checks and outputs the condition of the current temperature.

Take note that this process will trigger the LED and buzzer if abnormal condition is present.

Returns 1 upon success.

=cut

sub check_temperature {
    my ( $water_monitor, $current_reading ) = @_;
    my $temperature_range = $water_monitor->temperature_threshold;

    $water_monitor->current_temperature( $current_reading );

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

    } else {
        print "  Temperature is normal.\n";
    }
    1;
}

=head2 check_turbidity ( $water_monitor, $current_turbidity_reading )

This checks and outputs the condition of the current temperature.

Take note that this process will trigger the LED and buzzer if abnormal condition is present.

Returns 1 upon success.

=cut

sub check_turbidity {
    my ( $water_monitor, $current_reading ) = @_;
    my $turbidity_threshold = $water_monitor->turbidity_threshold;

    $water_monitor->current_turbidity( $current_reading );

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

        print "  Water is still clean.\n";
    }
    1;
}


=head2 check_water_filter ( $water_filter, $current_waste_count, $reduce_waste_by )

This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder.

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_water_filter {
    my $water_filter = shift;
    my $current_reading = shift;
    my $reduce_waste_by = shift || $water_filter->reduce_waste_count_by;
    my $waste_threshold = $water_filter->waste_count_threshold;

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

    } else {
        print "  Filtering cylinder is still clean.\n";
    }
    1;
}

=head2 check_water_level ( $water_level_maintainer, $current_water_level )

This checks, performs necessary actions and outputs the condition of the current waste count in the filtering cylinder.

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_water_level {
    my $water_level = shift;
    my $current_reading = shift;
    my $height_increase = $water_level->water_level_increase_height; # for output
    my $water_level_threshold = $water_level->low_water_level_threshold;

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

}

=head2 check_feeder ( $feeder, $verbose )

This checks, performs necessary actions and outputs the condition of the feeder. Each call will tick the clock inside the feeder. See C<Acme::FishFarm::Feeder> for more info.

If the food tank is empty, it will be filled to the default. So if you want to fill a different amount, please set the amount before hand. See C<Acme::FishFarm::Feeder>.

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

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

Currently this subroutine only shows the LEDs present in the  C<Acme::FishFarm::WaterConditionMonitor> object. See that module for more details about the available LEDs.

More LEDs will be available in the future.

=cut

sub render_leds {
    my $water_monitor = shift;

    # must check condition first! If not it won't work
        # this process will update the LEDs status
    $water_monitor->ph_is_normal;
    $water_monitor->temperature_is_normal;
    $water_monitor->lacking_oxygen;    
    $water_monitor->water_dirty;
        
    print "Total LEDs up: ", $water_monitor->lighted_LED_count, "\n";

    if ( $water_monitor->is_on_LED_pH ) {
        print "  pH LED: on\n";
    } else {

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

Default value is C<75>.

Sets the waste treshold.

This is the maximum limit of waste in the cylinder. When this count is hit, it will turn on the cleaners / spatulas or whatever it's called :).

=item reduce_waste_count_by

Default is C<10>.

The amount of waste to remove from the cylinder / filter each time the cleaning process is called.

=back

=cut

sub install {
    my $class = shift;
    my %options = @_;
    
    if ( not $options{current_waste_count} ) {

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


=cut

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

=head2 reduce_waste_count_by

Returns the amount of waste to be reduce each time the cleaning process is called.

=cut

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

=head2 set_waste_count_to_reduce ( $new_count )

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

}

=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;

t/02-fish_farm.t  view on Meta::CPAN

is( ref($feeder), "Acme::FishFarm::Feeder", "Correct feeder" );
is( ref($oxygen), "Acme::FishFarm::OxygenMaintainer", "Correct oxygem maintainer" );
is( ref($water_monitor), "Acme::FishFarm::WaterConditionMonitor", "Correct water condition monitor" );
is( ref($water_level), "Acme::FishFarm::WaterLevelMaintainer", "Correct water level monitor" );
is( ref($water_filter), "Acme::FishFarm::WaterFiltration", "Correct water filter" );

is( reduce_precision(3.14159), 3.141, "reduce_precision is working correctly" );
{
    local $@;
    eval { reduce_precision(3); };
    like( $@, qr/Please pass in a decimal value/, "reduce_precision can't process integers" );
}
is( reduce_precision(-12.53345), -12.533, "reduce_precision can work with negative decimal" );

ok( consume_oxygen( $oxygen, 2.5 ), "consume_oxygen is working correctly");
ok( consume_oxygen( $oxygen, 2 ), "consume_oxygen is working correctly");

ok( check_DO( $oxygen, 5 ), "check_DO is working correctly" );
ok( check_pH( $water_monitor, 5 ), "check_pH is working correctly" );
ok( check_temperature( $water_monitor, 25 ), "check_temperature is working correctly" );
ok( check_turbidity( $water_monitor, 250 ), "check_turbidity is working correctly" );

t/06-water_filtration.t  view on Meta::CPAN

$water_filter->current_waste_count(50);
is( $water_filter->current_waste_count, 50, "Correct new waste count" );
is( $water_filter->waste_count_threshold, 75, "Correct default waste count threshold" );
$water_filter->set_waste_count_threshold(100);
is( $water_filter->waste_count_threshold, 100, "Correct new waste count threshold" );

is( $water_filter->reduce_waste_count_by, 10, "Correct waste count reduction" );
$water_filter->set_waste_count_to_reduce(15);
is( $water_filter->reduce_waste_count_by, 15, "Correct new waste count reduction" );

# turn on spatulas, if not cleaning process will not happen
$water_filter->current_waste_count(10);

is( $water_filter->is_on_spatulas, 0, "Spatulas not on" );
$water_filter->clean_cylinder;
is( $water_filter->current_waste_count, 10, "Spatulas not on, can't clean anything" );
$water_filter->turn_on_spatulas;
is( $water_filter->is_on_spatulas, 1, "Spatulas switched on" );
$water_filter->clean_cylinder;
is( $water_filter->current_waste_count, 0, "Cylinder is totaly clean :)" );



( run in 0.324 second using v1.01-cache-2.11-cpan-8d75d55dd25 )