Coy3
Usage
# In your application:# ====================
use Coy;
warn "There seems to be a problem";
die "Looks like it might be fatal";
# You can add vocab in the $HOME/.coyrc file:# ===========================================
noun RESET; # REMOVE EXISTING noun VOCAB# WORKS FOR OTHER SPECIFIERS TOO
noun {wookie =>{category => [ Sentient ],sound => [ "roars", "grunts", "bellows" ],act =>{sits => { location => Arborial },
fights => { minimum => 2,association => "argument",},},},
};
category {Sentient =>{act =>{quarrels =>{associations => "argument",location => Terrestrial,minimum => 2,synonyms => [qw(bickers argues)],},laughs =>{associations => "happy",location => Terrestrial,non_adjectival => 1,},},}};
personage "R2D2";personage "Darth Vader";
place "Mos Eisley";place "the Death Star";
tree "Alderaan mangrove";fruit_tree "Wookie-oak";
# You can also select a different syllable counter via .coyrc# ===========================================================
use Lingua::EN::Syllables::syllable;syllable_counter "Lingua::EN::Syllables::syllable";
# or
use Lingua::EN::Syllables::syllable;syllable_counter \&Lingua::EN::Syllables::syllable;
# or
syllable_counter sub { return 1 }; # FAST BUT INACCURATE
Overview
Error messagesstrewn across my terminal.A vein starts to throb.
Their reproof adds theinjury of insult tothe shame of failure.
When a program dieswhat you need is a momentof serenity.
The Coy.pmmodule brings tranquillityto your debugging.
The module altersthe behaviour of C<die> andC<warn> (and C<croak> and C<carp>).
It also providesC<transcend> and C<enlighten> -- twoZen alternatives.
Like Carp.pm,Coy reports errors from thecaller's point-of-view.
But it prefacesthe bad news of failure witha soothing haiku.
The haiku are not"canned", but are generatedfreshly every time.
Once the haiku iscomplete, it's prepended tothe error message.
Execution ofthe original call toC<die> or C<warn> resumes.
Haiku and errormessage strew across my screen.A smile starts to form.
Extending the vocabulary
Any code placed in"$ENV{HOME}/.coyrc"runs at compile-time.
You can use that fileto extend Coy.pm'svocabulary.
The "SYNOPSIS" atthe start of this POD shows howyou might set it up.
(Eventuallythis section will detail thefull mechanism.)
Changing the syllable counter
Real haiku often <BR>have imperfect syllable<BR>counts.
The deficiencies of<BR>Coy's inbuilt counter are thus<BR>artistic virtues.
But some connoisseurs<BR>demand their syllable counts<BR>be always exact.
So if you don't like<BR>the syllable counter, Coy<BR>let's you replace it.
Coy provides a subcalled C<syllable_counter> forthat very purpose.
It is passed a subreference. That sub is then usedto count syllables.
You can also passthe sub's I<name> (that is, pass asymbolic reference).
The new counter subshould take a string and returnits syllable count.
C<syllable_counter>can be called from your code, orfrom .coyrc.
Bugs and limitations
In its current form,the module has four problemsand limitations:
* Vocabulary:The list of nouns and verbs istoo small at present.
This limits the rangeof topics that the haikuproduced can cover.
That in turn leads totell-tale repetition (whichfails the Turing test).
Extending the rangeof words Coy.pm canuse is no problem
(though finding the timeand the creativityrequired may be :-).
Users of Coy areencouraged to add their ownvocabulary.
(See the "SYNOPSIS",and also "EXTENDING THEVOCABULARY").
* Associations:The vocabulary hastoo few topic links.
Hence it's often notable to find relevantwords for a message.
This leads to haikuutterly unrelatedto the error text.
Again, there is notechnical difficultyin adding more links:
Defining enoughassociations isn'thard, just tedious.
User-specifiedvocabularies can solvethis problem as well.
* Limited grammar:The number of syntactictemplates is too small.
This leads to haikuthat are (structurally, atleast) monotonous.
Yet again, this needsno technical solution,just time and effort.
Of course, such enhancedtemplates might require richervocabulary.
For example, verbpredicates would need extradatabase structure:
Each verb entry wouldhave to be extended withlinks to object nouns.
* Syllable counting:This is perhaps the majorproblem at present.
The algorithmicsyllable counter is stillbeing developed.
It is currentlyaround 96%accurate (per word).
This means that correctsyllable counts for haikucan't be guaranteed.
Syllable counts forsingle words are correct toplus-or-minus 1.
In a multi-wordhaiku these errors cancelout in most cases.
Thus, the haiku tendto be correct within oneor two syllables.
As the syllablecounter slowly improves, thisproblem will abate.
Alteratively,you can choose to use your ownsyllable counter.
(See above in thesection titled "CHANGING THESYLLABLE COUNTER".)
Releases
2 releases since Debian 3.0 (Woody); the text changed 1 time.