From a44bfb158dac9e04647a75bc819a73bc18f5acce Mon Sep 17 00:00:00 2001
From: joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Date: Wed, 3 May 2006 19:58:58 +0000
Subject: [PATCH] change plugin interface to use named parameters for
 flexability

---
 IkiWiki.pm                    | 14 ++++++++------
 IkiWiki/Plugin/brokenlinks.pm |  3 ++-
 IkiWiki/Plugin/inline.pm      |  3 ++-
 IkiWiki/Plugin/orphans.pm     |  3 ++-
 IkiWiki/Plugin/pagecount.pm   |  3 ++-
 IkiWiki/Plugin/skeleton.pm    |  5 +++--
 IkiWiki/Render.pm             |  4 ++--
 7 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/IkiWiki.pm b/IkiWiki.pm
index e3bdc8d83..9a7b4fe91 100644
--- a/IkiWiki.pm
+++ b/IkiWiki.pm
@@ -7,7 +7,7 @@ use File::Spec;
 use HTML::Template;
 
 use vars qw{%config %links %oldlinks %oldpagemtime %pagectime
-            %renderedfiles %pagesources %depends %plugins};
+            %renderedfiles %pagesources %depends %hooks};
 
 sub checkconfig () { #{{{
 	if ($config{cgi} && ! length $config{url}) {
@@ -387,12 +387,14 @@ sub globlist_match ($$) { #{{{
 	return 0;
 } #}}}
 
-sub register_plugin ($$$) { # {{{
-	my $type=shift;
-	my $command=shift;
-	my $function=shift;
+sub hook (@) { # {{{
+	my %param=@_;
 	
-	$plugins{$type}{$command}=$function;
+	if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
+		error "hook requires type, call, and id parameters";
+	}
+	
+	$hooks{$param{type}}{$param{id}}=\%param;
 } # }}}
 
 1
diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm
index 75c819d76..8b91391fe 100644
--- a/IkiWiki/Plugin/brokenlinks.pm
+++ b/IkiWiki/Plugin/brokenlinks.pm
@@ -7,7 +7,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
-	IkiWiki::register_plugin("preprocess", "brokenlinks", \&preprocess);
+	IkiWiki::hook(type => "preprocess", id => "brokenlinks",
+		call => \&preprocess);
 } # }}}
 
 sub preprocess (@) { #{{{
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index c554774f6..61b4a8523 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -7,7 +7,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
-	IkiWiki::register_plugin("preprocess", "inline", \&IkiWiki::preprocess_inline);
+	IkiWiki::hook(type => "preprocess", id => "inline", 
+		call => \&IkiWiki::preprocess_inline);
 } # }}}
 
 # Back to ikiwiki namespace for the rest, this code is very much
diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm
index bd3c6b8b9..945892d17 100644
--- a/IkiWiki/Plugin/orphans.pm
+++ b/IkiWiki/Plugin/orphans.pm
@@ -7,7 +7,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
-	IkiWiki::register_plugin("preprocess", "orphans", \&preprocess);
+	IkiWiki::hook(type => "preprocess", id => "orphans",
+		call => \&preprocess);
 } # }}}
 
 sub preprocess (@) { #{{{
diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm
index fc69e449b..8a1376e09 100644
--- a/IkiWiki/Plugin/pagecount.pm
+++ b/IkiWiki/Plugin/pagecount.pm
@@ -7,7 +7,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
-	IkiWiki::register_plugin("preprocess", "pagecount", \&preprocess);
+	IkiWiki::hook(type => "preprocess", id => "pagecount", 
+		call => \&preprocess);
 } # }}}
 
 sub preprocess (@) { #{{{
diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm
index c9a7a421d..89308c45f 100644
--- a/IkiWiki/Plugin/skeleton.pm
+++ b/IkiWiki/Plugin/skeleton.pm
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # Ikiwiki skeleton plugin. Replace "skeleton" with the name of your plugin
-# in the lines below, and flesh out the methods to make it do something.
+# in the lines below, and flesh out the code to make it do something.
 package IkiWiki::Plugin::skeleton;
 
 use warnings;
@@ -8,7 +8,8 @@ use strict;
 use IkiWiki;
 
 sub import { #{{{
-	IkiWiki::register_plugin("preprocess", "skeleton", \&preprocess);
+	IkiWiki::hook(type => "preprocess", id => "skeleton", 
+		call => \&preprocess);
 } # }}}
 
 sub preprocess (@) { #{{{
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index be6e6d1cb..f90f16335 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -134,12 +134,12 @@ sub preprocess ($$) { #{{{
 		if (length $escape) {
 			return "[[$command $params]]";
 		}
-		elsif (exists $plugins{preprocess}{$command}) {
+		elsif (exists $hooks{preprocess}{$command}) {
 			my %params;
 			while ($params =~ /(\w+)=\"([^"]+)"(\s+|$)/g) {
 				$params{$1}=$2;
 			}
-			return $plugins{preprocess}{$command}->(page => $page, %params);
+			return $hooks{preprocess}{$command}{call}->(page => $page, %params);
 		}
 		else {
 			return "[[$command not processed]]";
-- 
2.39.5