Acme-Cow
view release on metacpan or search on metacpan
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
$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.
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.
=over 4
=item Parameters
(optional) A scalar; true if you want it to fill and adjust, false
otherwise.
=item Returns
=cut
sub as_string
{
my $self = shift;
my $tmpl = shift;
if (not $tmpl) {
if (defined $self->{'File'}) {
$tmpl = _slurp_file($self->{'File'});
} else {
$tmpl = $Acme::Cow::default_cow;
}
}
my $b = $self->_create_balloon();
my $template = new Text::Template(TYPE => 'STRING', SOURCE => $tmpl);
chomp($Acme::Cow::_private::balloon = $b->as_string());
$Acme::Cow::_private::el = $self->{'el'};
$Acme::Cow::_private::er = $self->{'er'};
$Acme::Cow::_private::U = $self->{'U'};
$Acme::Cow::_private::tl = ($self->{'mode'} eq 'think') ? 'o' : '\\';
$Acme::Cow::_private::tr = ($self->{'mode'} eq 'think') ? 'o' : '/';
=head1 WRITING YOUR OWN COW FILES
First, get comfortable with C<Text::Template> and its capabilities.
{$balloon} is the text balloon; it should be on a line by itself,
flush-left. {$tl} and {$tr} are what goes to the text balloon from
the thinking/speaking part of the picture; {$tl} is a backslash
("\") for speech, while {$tr} is a slash ("/"); both are a lowercase
letter O ("o") for thought. {$el} is a left eye, and {$er} is a
right eye; both are "o" by default. Finally {$U} is a tongue,
because a capital U looks like a tongue. (Its default value is "U ".)
Escape all other curly-braces within the ASCII art with backslashes.
There are two methods to make your own cow file: the standalone
file and the Perl module.
For the standalone file, take your piece of ASCII art and modify
it according to the C<Text::Template> rules above. Note that the
balloon must be flush-left in the template if you choose this method.
If the balloon isn't meant to be flush-left in the final output,
use its C<over()> method.
Cow/TextBalloon.pm
Cow/TuxStab.pm
MANIFEST
Makefile.PL
README
cows/bong.cow
cows/bunny.cow
cows/cheese.cow
cows/cower.cow
cows/daemon.cow
cows/default.cow
cows/dragon.cow
cows/elephant-in-snake.cow
cows/elephant.cow
cows/eyes.cow
cows/flaming-sheep.cow
cows/ghostbusters.cow
cows/head-in.cow
cows/hellokitty.cow
cows/jkh.cow
cows/kiss.cow
cow saying the given message on standard output.
To aid in the use of arbitrary messages with arbitrary whitespace,
B<-n> option. If it is specified, the given message will not be
word-wrapped. This is possibly useful if you want to make the cow
think or speak in B<figlet(6)>. If B<-n> is specified, there must
not be any command-line arguments left after all the switches have
been processed.
The B<-W> specifies roughly (where the message should be wrapped.
The default is equivalent to invoking with B<-W 40>, i.e. wrap
words at or before the 40th column.
If any command-line arguments are left over after all switches have
been processed, they become the cow's message. The program will
not accept standard input for a message in this case.
There are several provided modes which change the appearance of
the cow depending on its particular emotional/physical state. The
B<-b> option initiates Borg mode; B<-d> causes the cow to appear
dead; B<-g> invokes greedy mode; B<-p> causes a state of paranoia
to come over the cow; B<-s> makes the cow appear thoroughly stoned;
B<-t> yields a tired cow; B<-w> is somewhat the opposite of B<-t>,
and initiates wired mode; B<-y> brings on the cow's youthful
appearance.
The user may specify the B<-e> option to select the appearance of
the cow's eyes, in which case the first two characters of the
argument string I<eyes> will be used. The default eyes are 'oo'.
The tongue is similarly configurable through B<-T>; it must be two
characters and does not appear by default. However, it does appear
in the 'dead' and 'stoned' modes. Any configuration done by B<-e>
and B<-T> will be lost if one of the provided modes is used.
The B<-f> option specifies a particular cow picture file ("cowfile")
to use. If the cowfile spec contains a slash ("/") then it will
be interpreted as a path relative to the current directory.
Otherwise, cowsay will first search C<@INC> for installed cows
under the C<Acme::Cow::> hierarchy, and then search the path
specified in the C<COWPATH> environment variable. To list all
cowfiles installed as modules (in C<@INC>) and on the current
cow saying the given message on standard output.
To aid in the use of arbitrary messages with arbitrary whitespace,
B<-n> option. If it is specified, the given message will not be
word-wrapped. This is possibly useful if you want to make the cow
think or speak in B<figlet(6)>. If B<-n> is specified, there must
not be any command-line arguments left after all the switches have
been processed.
The B<-W> specifies roughly (where the message should be wrapped.
The default is equivalent to invoking with B<-W 40>, i.e. wrap
words at or before the 40th column.
If any command-line arguments are left over after all switches have
been processed, they become the cow's message. The program will
not accept standard input for a message in this case.
There are several provided modes which change the appearance of
the cow depending on its particular emotional/physical state. The
B<-b> option initiates Borg mode; B<-d> causes the cow to appear
dead; B<-g> invokes greedy mode; B<-p> causes a state of paranoia
to come over the cow; B<-s> makes the cow appear thoroughly stoned;
B<-t> yields a tired cow; B<-w> is somewhat the opposite of B<-t>,
and initiates wired mode; B<-y> brings on the cow's youthful
appearance.
The user may specify the B<-e> option to select the appearance of
the cow's eyes, in which case the first two characters of the
argument string I<eyes> will be used. The default eyes are 'oo'.
The tongue is similarly configurable through B<-T>; it must be two
characters and does not appear by default. However, it does appear
in the 'dead' and 'stoned' modes. Any configuration done by B<-e>
and B<-T> will be lost if one of the provided modes is used.
The B<-f> option specifies a particular cow picture file ("cowfile")
to use. If the cowfile spec contains a slash ("/") then it will
be interpreted as a path relative to the current directory.
Otherwise, cowsay will first search C<@INC> for installed cows
under the C<Acme::Cow::> hierarchy, and then search the path
specified in the C<COWPATH> environment variable. To list all
cowfiles installed as modules (in C<@INC>) and on the current
( run in 0.498 second using v1.01-cache-2.11-cpan-0a6323c29d9 )