NAME
Acme::Cow::Example - How to write a "derived cow"
SYNOPSIS
package Acme::Cow::MyCow;
use Acme::Cow;
@Acme::Cow::MyCow::ISA = qw(Acme::Cow);
my $my_cow = <<'EOC';
... template goes here ...
EOC
sub new { ... }
sub as_string { ... }
DESCRIPTION
First, put together your template as described in Acme::Cow, using Text::Template as a reference. It is recommended that you store this template in a variable in your package's namespace. Your template should not have tab characters in it. This will cause ugly things to happen.
Your new
method will likely want to look a lot like this:
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
my $self = $class->SUPER::new();
return $self;
}
Assuming you stored the template as $my_cow
then your as_string
method will likely want to be like this:
sub as_string
{
my $self = shift;
return $self->SUPER::as_string($my_cow);
}
Below, we present the actual code in this module, so you can see it in action. Yes, you can use this module to produce ASCII art. No, it won't be very exciting.
Acme::Cow::Example code
package Acme::Cow::Example;
use strict;
use Acme::Cow;
@Acme::Cow::Example::ISA = qw(Acme::Cow);
my $generic_ascii_art = <<'EOC';
{$balloon}
{$tr}
{$el}{$er} {$tr}
___________________
/ Insert cute ASCII \
\ artwork here. /
-------------------
{$U}
EOC
sub new
{
my $proto = shift;
my $class = ref $proto || $proto;
my $self = $class->SUPER::new();
$self->over(24);
return $self;
}
sub as_string
{
my $self = shift;
return $self->SUPER::as_string($generic_ascii_art);
}
HIGHLIGHTS
The {$balloon}
directive is flush left, but due to the call to over()
in the new()
method, it will be shoved over 24 spaces to the right, to line up with the thought/speech lines (represented by {$tr}
).
SAVING WORK
Included with the Acme::Cow
distribution is a short program called cowpm
which takes care of most of the boilerplate stuff for you. It's almost as simple as just add ASCII art but there's still a bit that you have to fill in. It has its own documentation; you should peruse cowpm.
SEE ALSO
AUTHOR
Tony Monroe <tmonroe plus perl at nog dot net>
BUGS
Very few.