Example

NAME

Acme::Cow::Example - How to write a "derived cow"

SYNOPSIS

use Acme::Cow;
  class Acme::Cow::MyCow is Acme::Cow {
my $my_cow = Q:to/EOC/;
  ... template goes here ...
  EOC
method new(|c) { callwith( ..., |c ) }
  method as_string { callwith($my_cow) }

DESCRIPTION

First, put together your template as described in Acme::Cow. It is recommended that you store this template in a variable. 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:

method new(|c) { callwith( ..., |c ) }

The ... indicates any additional overrides you need. If there are none, you can skip creating your own new method altogether. Overrides can be specified just the same as your call to new. For instance, if you want to have a default of 24 for the over attribute:

method new(|c) { callwith( over => 24, |c ) }

Assuming you stored the template as $my_cow then your as_string method will likely want to be like this:

method as_string() { callwith($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

unit class Acme::Cow::Example:ver<0.0.5>:auth<zef:lizmat> is Acme::Cow;
my $generic_ascii_art = Q:to/EOC/;
  {$balloon}
                         {$tr} 
       {$el}{$er}               {$tr}
   ___________________
  / Insert cute ASCII \
  \ artwork here.     /
   -------------------
        {$U}
  EOC
method new(|c) { callwith( over => 24, |c ) }
  method as_string() { callwith($my_cow) }

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

Acme::Cow, cowpm

AUTHOR

Elizabeth Mattijsen <[email protected]>

COPYRIGHT AND LICENSE

Original Perl 5 version: Copyright 2002 Tony McEnroe, Raku adaptation: Copyright 2019, 2021 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

Acme::Cow v0.0.5

Talking barnyard animals (or ASCII art in general)

Authors

  • Elizabeth Mattijsen

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Acme::Cow
  • Acme::Cow::DragonAndCow
  • Acme::Cow::Example
  • Acme::Cow::Frogs
  • Acme::Cow::MechAndCow
  • Acme::Cow::Stegosaurus
  • Acme::Cow::TextBalloon
  • Acme::Cow::TuxStab

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.