} #}}}
package IkiWiki::RPC::XML;
+use Memoize;
sub getvar ($$$) { #{{{
my $plugin=shift;
IkiWiki::Plugin::external::rpc_call($plugin, $params{call}, @_)
};
eval qq{*$params{name}=\$sub};
+ memoize($params{name}) if $params{memoize};
return 1;
} #}}}
"Ikiwiki::rcs_update" and "call" is the RPC call ikiwiki will make whenever
that function is run.
+If the RPC call is memoizable, you can also pass a "memoize" parameter, set
+to 1.
+
## Limitations of XML RPC
Since XML RPC can't pass around references to objects, it can't be used
Injecting a replacement for a commonly called ikiwiki function
could result in a lot more RPC calls than expected and slow
eveything down. `pagetitle`, for instance, is called about 100 times
-per page build.
+per page build. Memoizing injected functions whenever possible is a very
+good idea.
In general, use common sense, and your external plugin will probably
perform ok.
# 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.
- rpc_call("inject", name => "IkiWiki::bob", call => "bob");
+ # 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.
print STDERR "url is set to: ".