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