actually, Sledge does not have real plugin system..
currently, typical plugin codes are below.
write sub import {} and modify symbol tables directly.
package Sledge::Plugin::Foo;
use strict;
sub import {
my $class = shift;
my $pkg = caller;
no strict 'refs';
*{"$pkg\::foo"} = sub {
# do something
};
$pkg->register_hook(
AFTER_DISPATCH => sub {
# do something.
},
);
}
I think this style is slightly complex..
so, I propose some modules to write plugins easily.
use Sledge::Plugin as a baseclass.
package Sledge::Plugin::Bar;
use strict;
use base qw(Sledge::Plugin);
__PACKAGE__->add_methods(
plugin_method => sub {
my $self = shift;
#...
},
);
__PACKAGE__->register_hooks(
AFTER_DISPATCH => sub {
my $self = shift;
#...
},
);
in your Pages, use Sledge::PluginLoader.
package MyApp::Pages::Root;
use strict;
use base qw(MyApp::Pages::Base);
use Sledge::PluginLoader qw(Bar); # load Sledge::Plugin::Bar.
sub dispatch_index {
my $self = shift;
# You can call the method which provided by plugins.
$self->plugin_method;
}
write Sledge plugins more easily. 0 Comments More | Login | Reply /