change plugin interface to use named parameters for flexability
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 3 May 2006 19:58:58 +0000 (19:58 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Wed, 3 May 2006 19:58:58 +0000 (19:58 +0000)
IkiWiki.pm
IkiWiki/Plugin/brokenlinks.pm
IkiWiki/Plugin/inline.pm
IkiWiki/Plugin/orphans.pm
IkiWiki/Plugin/pagecount.pm
IkiWiki/Plugin/skeleton.pm
IkiWiki/Render.pm

index e3bdc8d83c8739b9e3a140788026aca2d58ab306..9a7b4fe911a284f7a11dfc19060ffbddef2b2401 100644 (file)
@@ -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
index 75c819d761d871d1c73948138a765a01463ecbb4..8b91391fe784d3cda973cb6a465cd199683ce4be 100644 (file)
@@ -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 (@) { #{{{
index c554774f6c23f1257d63a46bad8376d2e7eee82b..61b4a8523f2dfaf9156238b0ab54adedc9f77b42 100644 (file)
@@ -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
index bd3c6b8b9f8e4157856417847458832fbe731d26..945892d177d7723bbd0ac579bcd0da36a40fd147 100644 (file)
@@ -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 (@) { #{{{
index fc69e449bb2612ee6afb73f95b4d9977448afbb5..8a1376e09a022fb7be70ab3421a07693613dfa83 100644 (file)
@@ -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 (@) { #{{{
index c9a7a421d4c5b67e16cd14162f735f375a16e684..89308c45fb973fbf3a6643a14d86b6f2e3cc684b 100644 (file)
@@ -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 (@) { #{{{
index be6e6d1cbe8b5e09b0c5e626bb6d8c44023e7519..f90f16335ead61cf034b4f78da8872b775fd6dd2 100644 (file)
@@ -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]]";