]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki.pm
* Add a run_hooks function for the common task of running all hooks of a
[ikiwiki.git] / IkiWiki.pm
index d369d7da839589f3d440a47e083a241e3cf45389..54ca845501d0396e1893b70ed61e0b98da6a75db 100644 (file)
@@ -93,11 +93,7 @@ sub checkconfig () { #{{{
                require IkiWiki::Rcs::Stub;
        }
 
-       if (exists $hooks{checkconfig}) {
-                foreach my $id (keys %{$hooks{checkconfig}}) {
-                        $hooks{checkconfig}{$id}{call}->();
-                }
-        }
+       run_hooks(checkconfig => sub { shift->() });
 } #}}}
 
 sub loadplugins () { #{{{
@@ -503,4 +499,17 @@ sub hook (@) { # {{{
        $hooks{$param{type}}{$param{id}}=\%param;
 } # }}}
 
+sub run_hooks ($$) { # {{{
+       # Calls the given sub for each hook of the given type,
+       # passing it the hook function to call.
+       my $type=shift;
+       my $sub=shift;
+
+       if (exists $hooks{$type}) {
+               foreach my $id (keys %{$hooks{$type}}) {
+                       $sub->($hooks{$type}{$id}{call});
+               }
+       }
+} #}}}
+
 1