needsbuild hook is passed an array ref
[ikiwiki] / IkiWiki / Plugin / fortune.pm
1 #!/usr/bin/perl
2 # Include a fortune in a page
3 package IkiWiki::Plugin::fortune;
4
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
8
9 sub import {
10         hook(type => "getsetup", id => "fortune", call => \&getsetup);
11         hook(type => "preprocess", id => "fortune", call => \&preprocess);
12 }
13
14 sub getsetup () {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => undef,
19                         section => "widget",
20                 },
21 }
22
23 sub preprocess (@) {
24         $ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games";
25         my $f = `fortune 2>/dev/null`;
26
27         if ($?) {
28                 error gettext("fortune failed");
29         }
30         else {
31                 return "<pre>$f</pre>\n";
32         }
33 }
34
35 1