change example to override a real function

master
Joey Hess 2008-10-21 17:09:57 -04:00
parent 70e0c9447a
commit 92a43d5d38
1 changed files with 9 additions and 8 deletions

View File

@ -101,16 +101,16 @@ sub import {
# stage of ikiwiki. # stage of ikiwiki.
rpc_call("hook", type => "preprocess", id => "externaldemo", call => "preprocess"); rpc_call("hook", type => "preprocess", id => "externaldemo", call => "preprocess");
# Here's an example of how to inject an arbitrary function into
# ikiwiki. Ikiwiki will be able to call bob() just like any other
# function. Note use of automatic memoization.
rpc_call("inject", name => "IkiWiki::bob", call => "bob",
memoize => 1);
# Here's an exmaple of how to access values in %IkiWiki::config. # Here's an exmaple of how to access values in %IkiWiki::config.
print STDERR "url is set to: ". print STDERR "url is set to: ".
rpc_call("getvar", "config", "url")."\n"; rpc_call("getvar", "config", "url")."\n";
# Here's an example of how to inject an arbitrary function into
# ikiwiki, replacing a core function.
# Note use of automatic memoization.
rpc_call("inject", name => "IkiWiki::formattime",
call => "formattime", memoize => 1);
print STDERR "externaldemo plugin successfully imported\n"; print STDERR "externaldemo plugin successfully imported\n";
} }
@ -126,8 +126,9 @@ sub preprocess {
return "externaldemo plugin preprocessing on $title!"; return "externaldemo plugin preprocessing on $title!";
} }
sub bob { sub formattime {
print STDERR "externaldemo plugin's bob called via RPC"; print STDERR "externaldemo plugin's formattime called via RPC";
return scalar "formatted time: ".localtime(shift);
} }
# Now all that's left to do is loop and handle each incoming RPC request. # Now all that's left to do is loop and handle each incoming RPC request.