Acme::Cow::Example - How to write a "derived cow"
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 { ... }
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:
new
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:
$my_cow
as_string
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.
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); }
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}).
{$balloon}
over()
new()
{$tr}
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.
Acme::Cow
cowpm
Acme::Cow, cowpm
Tony Monroe <tmonroe plus perl at nog dot net>
Very few.
To install Acme::Cow, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Acme::Cow
CPAN shell
perl -MCPAN -e shell install Acme::Cow
For more information on module installation, please visit the detailed CPAN module installation guide.