add section information
[ikiwiki] / IkiWiki / Plugin / testpagespec.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::testpagespec;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "getsetup", id => "testpagespec", call => \&getsetup);
10         hook(type => "preprocess", id => "testpagespec", call => \&preprocess);
11 }
12
13 sub getsetup () {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                         section => "special-purpose",
19                 },
20 }
21
22 sub preprocess (@) {
23         my %params=@_;
24         
25         foreach my $param (qw{match pagespec}) {
26                 if (! exists $params{$param}) {
27                         error sprintf(gettext("%s parameter is required"), $param);
28                 }
29         }
30
31         add_depends($params{page}, $params{pagespec});
32         
33         my $ret=pagespec_match($params{match}, $params{pagespec}, 
34                         location => $params{page});
35         if ($ret) {
36                 return "match: $ret";
37         }
38         else {
39                 return "no match: $ret";
40         }
41 }
42
43 1