Acme-Llama

 view release on metacpan or  search on metacpan

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

use strict;
use warnings;

package Acme::Llama;

our %llama;

=head1 NAME

Acme::Llama - An object-oriented interface to llamas.

=head1 VERSION

Version 0.42

=head1 SYNOPSIS

use strict;
use warnings;
use Acme::Llama;
my $llama = Acme::Llama->new;
$llama->feed;
$llama->play;
$llama->sacrifice;

=head1 DESCRIPTION

This module provides a simplistic, but powerful, interface to the Lama glama.

=head1 OBJECT INTERFACE

=over

=item B<new>

Create a new llama, all by yourself! :)

=cut

sub new {
    my $class = shift;
    my $self = bless {}, $class;
    $llama{'foodage'}   = 0;
    $llama{'happiness'} = 0;
    $llama{'tired'}     = 0;
    return $self;
}

=item B<feed>

A well-fed llama is a happy llama.
The perl Gods like happy llamas.
Too much food makes a sad llama though. :(
No one likes a sad llama.

[Technical details: returns 1 for a happy hungry llama, and returns
for a big full llama. ]

=cut

sub feed {
    $llama{'foodage'}++;
    if   ( $llama{'foodage'} < 10 ) { $llama{'happiness'}++ and return 1; }
    else                            { $llama{'happiness'}-- and return; }
}

=item B<play>

A good llama trainer should play often with their llama, 
as this makes them happy.
Llamas get tired though, and then they don't like to play,
they need rest instead then.

[Technical details: returns 1 for a llama that wants to play more,
and returns for a llama that needs a nap. ]

=cut

sub play {
    if ( $llama{'tired'} == 1 ) {
        $llama{'happiness'} - 5;
        return;
    }
    my $int = int( rand(20) );
    $llama{'happiness'} + 2;
    if ( $int > 10 ) {
        $llama{'tired'} = 1;
        return;
    }
    else {
        $llama{'tired'} = 0;
        return 1;
    }
}

=item B<nap>

Sometimes, even the big llamas get tired.
When llamas are tired, they need a nap to make them 
feel better! But, if the llama isn't tired, making it
try to take a nap will make it a sad llama. :(



( run in 2.932 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )