nipotan's Journal nipotan's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:44:14+00:00 pudge Technology hourly 1 1970-01-01T00:00+00:00 nipotan's Journal Sledge::PluginLoader <a href=""></a> <br> It's cool.<br> <br> But, maybe <a href=""></a> is fault.<br> <br> The plugins will be exported via Sledge::PluginLoader.<br> <br> the implementation is like this:<blockquote><div><p> <tt>package Sledge::PluginLoader;<br> <br>use strict;<br>use warnings;<br>use Carp qw(croak);<br>use UNIVERSAL::require;<br> <br>sub import {<br>&nbsp; &nbsp; my $class = shift;<br>&nbsp; &nbsp; my $pkg = caller;<br> <br>&nbsp; &nbsp; for my $name (@_) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $plugin = "Sledge::Plugin::$name";<br>&nbsp; &nbsp; &nbsp; &nbsp; $plugin-&gt;require or croak $!;<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; unless ($plugin-&gt;can('add_methods') &amp;&amp; $plugin-&gt;can('register_hooks')) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; croak "$plugin is an old Sledge Plugin. use it directly";<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; my @method_info = $plugin-&gt;add_methods;<br>&nbsp; &nbsp; &nbsp; &nbsp; for (my $i = 0; $i &lt; @method_info; $i += 2) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; no strict 'refs';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; my $method_name = $method_info[$i];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *{"$pkg\::$method_name"} = $method_info[$i + 1];<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; my @hook_info = $plugin-&gt;resister_hooks;<br>&nbsp; &nbsp; &nbsp; &nbsp; for (my $i = 0; $i &lt; @hook_info; $i += 2) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $pkg-&gt;register_hook($hook_info[$i] =&gt; $hook_info[$i + 1])<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br> <br>1;</tt></p></div> </blockquote><p>I didn't try it. It's no guarantee<nobr> <wbr></nobr>:P<br> and this code lost the backward compatibility.<br> any idea?</p> nipotan 2006-11-17T07:59:02+00:00 others