diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-04-27 02:55:52 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-04-27 02:55:52 +0000 |
commit | ee1ad53c4c2710aa7ded61bdc56f3a8cce514f22 (patch) | |
tree | 85914bbbf7ac596f0fc001071c91f4e31db0b49e /IkiWiki/Plugin/conditional.pm | |
parent | 80aa0336e692ba9c63cb934d91bf5f1962507700 (diff) | |
download | ikiwiki-ee1ad53c4c2710aa7ded61bdc56f3a8cce514f22.tar ikiwiki-ee1ad53c4c2710aa7ded61bdc56f3a8cce514f22.tar.gz |
* pagespec_match() has changed to take named parameters, to better allow
for extended pagespecs. The old calling convention will still work for
back-compat for now.
* The calling convention for functions in the IkiWiki::PageSpec namespace
has changed so they are passed named parameters.
* Plugin interface version increased to 2.00 since I don't anticipate any
more interface changes before 2.0.
Diffstat (limited to 'IkiWiki/Plugin/conditional.pm')
-rw-r--r-- | IkiWiki/Plugin/conditional.pm | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/IkiWiki/Plugin/conditional.pm b/IkiWiki/Plugin/conditional.pm index 22057c135..29223ace2 100644 --- a/IkiWiki/Plugin/conditional.pm +++ b/IkiWiki/Plugin/conditional.pm @@ -3,12 +3,9 @@ package IkiWiki::Plugin::conditional; use warnings; use strict; -use IkiWiki; +use IkiWiki 2.00; use UNIVERSAL; -# Globals used to pass information into the PageSpec functions. -our ($sourcepage, $destpage); - sub import { #{{{ hook(type => "preprocess", id => "if", call => \&preprocess_if); } # }}} @@ -21,27 +18,28 @@ sub preprocess_if (@) { #{{{ } my $result=0; - $sourcepage=$params{page}; - $destpage=$params{destpage}; # An optimisation to avoid needless looping over every page # and adding of dependencies for simple uses of some of the # tests. if ($params{test} =~ /^(enabled|sourcepage|destpage)\((.*)\)$/) { - $result=eval "IkiWiki::PageSpec::match_$1(undef, ". - IkiWiki::safequote($2).", \$params{page})"; + $result=pagespec_match($params{page}, $params{test}, + location => $params{page}, + sourcepage => $params{page}, + destpage => $params{destpage}); } else { add_depends($params{page}, $params{test}); foreach my $page (keys %pagesources) { - if (pagespec_match($page, $params{test}, $params{page})) { + if (pagespec_match($page, $params{test}, + location => $params{page}, + sourcepage => $params{page}, + destpage => $params{destpage})) { $result=1; last; } } } - $sourcepage=""; - $destpage=""; my $ret; if ($result) { @@ -59,7 +57,7 @@ sub preprocess_if (@) { #{{{ package IkiWiki::PageSpec; -sub match_enabled ($$$) { #{{{ +sub match_enabled ($$;@) { #{{{ shift; my $plugin=shift; @@ -67,24 +65,31 @@ sub match_enabled ($$$) { #{{{ return UNIVERSAL::can("IkiWiki::Plugin::".$plugin, "import"); } #}}} -sub match_sourcepage ($$$) { #{{{ +sub match_sourcepage ($$;@) { #{{{ shift; my $glob=shift; - - return match_glob($IkiWiki::Plugin::conditional::sourcepage, $glob, - $IkiWiki::Plugin::conditional::sourcepage); + my %params=@_; + + return unless exists $params{sourcepage}; + return match_glob($params{sourcepage}, $glob, @_); } #}}} -sub match_destpage ($$$) { #{{{ +sub match_destpage ($$;@) { #{{{ shift; my $glob=shift; + my %params=@_; - return match_glob($IkiWiki::Plugin::conditional::destpage, $glob, - $IkiWiki::Plugin::conditional::sourcepage); + return unless exists $params{destpage}; + return match_glob($params{destpage}, $glob, @_); } #}}} -sub match_included ($$$) { #{{{ - return $IkiWiki::Plugin::conditional::sourcepage ne $IkiWiki::Plugin::conditional::destpage; +sub match_included ($$;$) { #{{{ + shift; + shift; + my %params=@_; + + return unless exists $params{sourcepage} && exists $params{destpage}; + return $params{sourcepage} ne $params{destpage}; } #}}} 1 |