Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ikebe (2247)

ikebe
  (email not shown publicly)
http://blog.shebang.jp/

Journal of ikebe (2247)

Monday November 13, 2006
09:23 AM

write Sledge plugins more easily.

[ #31589 ]

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;
}

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.