Acme-Cow
view release on metacpan or search on metacpan
package Acme::Cow;
use strict;
$Acme::Cow::VERSION = '0.2.1';
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
# Below is stub documentation for your module. You better edit it!
=head1 NAME
Acme::Cow - Talking barnyard animals (or ASCII art in general)
=head1 SYNOPSIS
use Acme::Cow;
$cow = new Acme::Cow;
$cow->say("Moo!");
$cow->print();
$sheep = new Acme::Cow::Sheep; # Derived from Acme::Cow
$sheep->wrap(20);
$sheep->think();
$sheep->text("Yeah, but you're taking the universe out of context.");
$sheep->print(\*STDERR);
$duck = new Acme::Cow(File => "duck.cow");
$duck->fill(0);
$duck->say(`figlet quack`);
$duck->print($socket);
=head1 DESCRIPTION
Acme::Cow is the logical evolution of the old cowsay program. Cows
are derived from a base class (Acme::Cow) or from external files.
Cows can be made to say or think many things, optionally filling
and justifying their text out to a given margin,
Cows are nothing without the ability to print them, or sling them
as strings, or what not.
=cut
use Acme::Cow::TextBalloon;
use IO::File;
use Text::Template;
$Acme::Cow::default_cow = <<'EOC';
{$balloon}
{$tl} ^__^
{$tl} ({$el}{$er})\_______
(__)\ )\/\
{$U} ||----w |
|| ||
EOC
=pod
=head1 METHODS
=head2 new
=over 4
=item Parameters
A list of key-value pairs. If you plan to use an external file as
the template, you probably want to say:
$x = new Acme::Cow(File => 'file.cow');
=item Returns
A blessed reference to an C<Acme::Cow>.
=back
=cut
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
my %args = @_;
my $self = {
wrap => 40,
mode => 'say',
fill => 1,
over => 0,
text => undef,
el => 'o',
er => 'o',
U => ' ',
%args,
};
bless $self, $class;
=item Parameters
(optional) A number.
=item Returns
The new value, if set; the existing value if not.
=item Notes
The number set here has no effect if you decline filling/adjusting
of the balloon text.
=back
=cut
sub wrap
{
my $self = shift;
if (@_) {
$self->{'wrap'} = $_[0];
}
return $self->{'wrap'};
}
=pod
=head2 think
Tell the cow to think its text instead of saying it.
=over 4
=item Parameters
(optional) Text to think.
=item Returns
None.
=back
=cut
sub think
{
my $self = shift;
$self->{'mode'} = 'think';
if (@_) {
$self->text(@_);
}
}
=pod
=head2 SAY
Tell the cow to say its text instead of thinking it.
=over 4
=item Parameters
(optional) Text to say.
=item Returns
None.
=back
=cut
sub say
{
my $self = shift;
$self->{'mode'} = 'say';
if (@_) {
$self->text(@_);
}
}
=pod
=head2 text
Set (or retrieve) the text that the cow will say or think.
=over 4
=item Parameters
A list of lines of text (optionally terminated with newlines) to
be displayed inside the balloon.
=item Returns
The new text, if set; the current text, if not.
=back
=cut
sub text
{
my $self = shift;
if (@_) {
my @l = @_;
$self->{'text'} = \@l;
}
return $self->{'text'};
}
=pod
=head2 print
Print a representation of the cow to the specified filehandle
(STDOUT by default).
=over 4
=item Parameters
(optional) A filehandle.
=item Returns
None.
=back
=cut
sub print
{
my $self = shift;
my $fh = shift || \*STDOUT;
print $fh $self->as_string();
}
=pod
=head2 fill
Inform the cow to fill and adjust (or not) the text inside its balloon.
By default, text inside the balloon is filled and adjusted.
( run in 2.754 seconds using v1.01-cache-2.11-cpan-364913b4093 )