|
Acme::Scurvy::Whoreson::BilgeRat - multi-lingual insult generator |
Acme::Scurvy::Whoreson::BilgeRat - multi-lingual insult generator
use Acme::Scurvy::Whoreson::BilgeRat;
my $insultgenerator = Acme::Scurvy::Whoreson::Bilgerat->new(
language => 'pirate'
);
print $insultgenerator; # prints a piratical insult
A multi-lingual insult generator, which takes pluggable backends to generate insults in the language of your choice, written in honour of International Talk Like A Pirate Day on Sept 19th 2003 http://www.talklikeapirate.com/. An example backend is provided which implements the 'pirate' language.
Usage is very simple. Instantiate an Acme::Scurvy::Whoreson::BilgeRat object, passing a single named parameter - 'language' - to the constructor. This tells it to use the A::S::W::B::Backend::[language] plugin module. If that is missing, we assume you want the 'pirate' backend.
To generate an insult, simply mention your object in any place where it will be turned into a string. It uses the AWESOME POWER of operator overloading to achieve this heroic feat.
So, on to the most complex part of all this, which thankfully isn't that complex.
To create a plugin, you create a bog-standard module, whose name is Acme::Scurvy::Whoreson::Bilgerat::Backend::[your language name]. It should be a subclass of A::S::W::B. The constructor should return a blessed object and must be called new(). You then have two options:
new() return
a blessed hashref with the following keys:
You may have words appearing in both the nouns and the adjectives lists. The default insult generator will ensure that it never uses the same word twice in any one insult. Of course, there are some situations where there are simply not enough nouns or adjectives in the grammar, in which case an empty insult is generated.
generateinsult() method. This is a bog-standard method, which will be
called with exactly one parameter - a reference to the object. You must
return a string from this method. How you generate that string is entirely
up to you, and you may need to do something different from what I have
described above in the constructor. The only limitation on the constructor
for a backend is that it *must* return something that inherits from A::S::W::B,
and it will not be supplied with any parameters at all other than its own
class name.
See the A::S::W::B::Backend::pirate module for an example.
No bugs are known, but if you find any please let me know, and send a test case and - if possible - a patch.
I welcome feedback about my code, including constructive criticism. And, while this is free software (both free-as-in-beer and free-as-in-speech) I also welcome payment. In particular, your bug reports will get moved to the front of the queue if you buy me something from my wishlist, which can be found at http://www.cantrell.org.uk/david/shopping-list/wishlist.
David Cantrell <david@cantrell.org.uk>
Copyright 2003 David Cantrell
This module is free-as-in-speech software, and may be used, distributed, and modified under the same terms as Perl itself.
|
Acme::Scurvy::Whoreson::BilgeRat - multi-lingual insult generator |