summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/haiku.pm
blob: 0e93e9d8d2bccb553fb509cddaa9d11733284506 (plain)
  1. #!/usr/bin/perl
  2. # haiku generator plugin
  3. package IkiWiki::Plugin::haiku;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. sub import { #{{{
  8. IkiWiki::hook(type => "preprocess", id => "haiku",
  9. call => \&preprocess);
  10. } # }}}
  11. sub preprocess (@) { #{{{
  12. my %params=@_;
  13. my $haiku;
  14. eval q{use Coy};
  15. if ($@) {
  16. my @canned=(
  17. "The lack of a Coy:
  18. No darting, subtle haiku.
  19. Instead, canned tuna.
  20. ",
  21. "apt-get install Coy
  22. no, wait, that's not quite it
  23. instead: libcoy-perl
  24. ",
  25. "Coyly I'll do it,
  26. no code, count Five-Seven-Five
  27. to make a haiku.
  28. ",
  29. );
  30. $haiku=$canned[rand @canned];
  31. }
  32. else {
  33. # Coy is rather strange, so the best way to get a haiku
  34. # out of it is to die..
  35. eval {die exists $params{hint} ? $params{hint} : $params{page}};
  36. $haiku=$@;
  37. # trim off other text
  38. $haiku=~s/\s+-----\n//s;
  39. $haiku=~s/\s+-----.*//s;
  40. }
  41. $haiku=~s/^\s+//mg;
  42. $haiku=~s/\n/<br>\n/mg;
  43. return $haiku
  44. } # }}}
  45. 1