diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-10-21 17:57:19 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-10-21 17:57:19 -0400 |
commit | e75818572fff5256d16221a2b065b214d8cb9f5d (patch) | |
tree | 30e45561111b4dcc48f4726bfaef0ca99f5d47d2 /IkiWiki/Plugin | |
parent | 92a43d5d384ba4e504c5255989a869ced424219c (diff) |
function injection overhaul
Add an inject function, that can be used by plugins that want to replace
one of ikiwiki's functions with their own version. (This is a scary thing
that grubs through the symbol table, and replaces all exported occurances
of a function with the injected version.)
external: RPC functions can be injected to replace exported functions.
Removed the stupid displaytime hook, and use injection instead.
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/external.pm | 8 | ||||
-rw-r--r-- | IkiWiki/Plugin/relativedate.pm | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/external.pm b/IkiWiki/Plugin/external.pm index 287e118f1..4ce9c8bab 100644 --- a/IkiWiki/Plugin/external.pm +++ b/IkiWiki/Plugin/external.pm @@ -202,10 +202,16 @@ sub inject ($@) { #{{{ my $sub = sub { IkiWiki::Plugin::external::rpc_call($plugin, $params{call}, @_) }; + $sub=memoize($sub) if $params{memoize}; + + # This will add it to the symbol table even if not present. no warnings; eval qq{*$params{name}=\$sub}; use warnings; - memoize($params{name}) if $params{memoize}; + + # This will ensure that everywhere it was exported to sees + # the injected version. + IkiWiki::inject(name => $params{name}, call => $sub); return 1; } #}}} diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index f4dba61a4..dc8f7d538 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -12,7 +12,7 @@ sub import { #{{{ add_underlay("javascript"); hook(type => "getsetup", id => "relativedate", call => \&getsetup); hook(type => "format", id => "relativedate", call => \&format); - hook(type => "displaytime", id => "relativedate", call => \&display); + inject(name => "IkiWiki::displaytime", call => \&mydisplaytime); } # }}} sub getsetup () { #{{{ @@ -43,7 +43,7 @@ sub include_javascript ($;$) { #{{{ '" type="text/javascript" charset="utf-8"></script>'; } #}}} -sub display ($;$) { #{{{ +sub mydisplaytime ($;$) { #{{{ my $time=shift; my $format=shift; |