nipotan's Journal http://use.perl.org/~nipotan/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 pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 nipotan's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~nipotan/journal/ Sledge::PluginLoader http://use.perl.org/~nipotan/journal/31639?from=rss <a href="http://use.perl.org/~ikebe/journal/31589">http://use.perl.org/~ikebe/journal/31589</a> <br> It's cool.<br> <br> But, maybe <a href="http://use.perl.org/~tokuhirom/journal/31638">http://use.perl.org/~tokuhirom/journal/31638</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