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