]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/haiku.pm
web commit by http://id.loopysoft.com/matt/
[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 2.00;
9 sub import { #{{{
10         hook(type => "preprocess", id => "haiku", call => \&preprocess);
11 } # }}}
13 sub preprocess (@) { #{{{
14         my %params=@_;
16         my $haiku;
17         eval q{use Coy};
18         if ($@ || ! Coy->can("Coy::with_haiku")) {
19                 my @canned=(
20                         "The lack of a Coy:
21                          No darting, subtle haiku.
22                          Instead, canned tuna.
23                         ",
24                         "apt-get install Coy
25                          no, wait, that's not quite it
26                          instead: libcoy-perl
27                         ",
28                         "Coyly I'll do it,
29                          no code, count Five-Seven-Five
30                          to make a haiku.
31                         ",
32                 );
33                                          
34                 $haiku=$canned[rand @canned];
35         }
36         else {
37                 $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
38                 
39                 # trim off other text
40                 $haiku=~s/\s+-----\n//s;
41                 $haiku=~s/\s+-----.*//s;
42         }
43                 
44         $haiku=~s/^\s+//mg;
45         $haiku=~s/\n/<br>\n/mg;
46         
47         return "\n\n<blockquote>$haiku</blockquote>\n\n";
48 } # }}}
50 1