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 ]

tokuhirom (7396)

tokuhirom
  (email not shown publicly)
http://d.hatena.ne.jp/tokuhirom/

Journal of tokuhirom (7396)

Friday November 17, 2006
02:25 AM

implementation of Sledge::Plugin.

[ #31638 ]

http://use.perl.org/~ikebe/journal/31589

here is implementation.

package Sledge::Plugin;
use strict;
use warnings;
use base qw/Class::Data::Inheritable/;
 
__PACKAGE__->mk_classdata('methods');
__PACKAG E__->mk_classdata('hooks');
 
sub import {
    my $class = shift;
    my $pkg = caler(0);
 
    # add methods
    while (my ($name, $code) = each %{$class->methods || {}} ) {
        no stirct 'refs';
        *{"$pkg\::$name"} = $code;
    }
 
    # register hooks
    $class->register_hooks( %{ $class->hooks || {} } );
}
 
sub add_methods {
    my ($class, %d) = @_;
 
    $class->methods(
        {
        %{ $class->methods || {} },
        %d,
    }
    );
}
 
sub register_hooks {
    my ($class, %d) = @_;
 
    $class->hooks(
        {
        %{ $class->hooks || {} },
        %d,
        }
    );
}
 
1;

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.