package Sledge::PluginLoader;
use strict;
use warnings;
use Carp qw(croak);
use UNIVERSAL::require;
sub import {
my $class = shift;
my $pkg = caller;
for my $name (@_) {
my $plugin = "Sledge::Plugin::$name";
$plugin->require or croak $!;
unless ($plugin->can('add_methods') && $plugin->can('register_hooks')) {
croak "$plugin is an old Sledge Plugin. use it directly";
}
my @method_info = $plugin->add_methods;
for (my $i = 0; $i < @method_info; $i += 2) {
no strict 'refs';
my $method_name = $method_info[$i];
*{"$pkg\::$method_name"} = $method_info[$i + 1];
}
my @hook_info = $plugin->resister_hooks;
for (my $i = 0; $i < @hook_info; $i += 2) {
$pkg->register_hook($hook_info[$i] => $hook_info[$i + 1])
}
}
}
1;
I didn't try it. It's no guarantee
and this code lost the backward compatibility.
any idea?