]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/haiku.pm
oops
[git.ikiwiki.info.git] / IkiWiki / Plugin / haiku.pm
1 #!/usr/bin/perl
2 # haiku generator plugin
3 package IkiWiki::Plugin::haiku;
5 use warnings;
6 use strict;
7 use IkiWiki;
9 sub import { #{{{
10         IkiWiki::hook(type => "preprocess", id => "haiku",
11                 call => \&preprocess);
12 } # }}}
14 sub preprocess (@) { #{{{
15         my %params=@_;
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                 $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
39                 
40                 # trim off other text
41                 $haiku=~s/\s+-----\n//s;
42                 $haiku=~s/\s+-----.*//s;
43         }
44                 
45         $haiku=~s/^\s+//mg;
46         $haiku=~s/\n/<br>\n/mg;
47         
48         return "\n\n<blockquote>$haiku</blockquote>\n\n";
49 } # }}}
51 1