
なんだかんだしてたら返事が遅れて超亀レスで申し訳ないですが
sexさんのsubtech - sexさんのブログ - Class::Component::Plugin の init()
init() っていうメソッドがたぶんabstract methodとしてあるっぽいんだけど、その中でなにも渡ってこないのが悔しい><
やるとすればComponentとしてnewした時にpluginを初期化する処理とか実装したほうがいいのかなぁ?と
例えば以下のようなComponentを用意して
package Class::Component::Component::PluginSetContext;
use strict;
use warnings;
use Scalar::Util ();
sub new {
my $class = shift;
my $self = $class->NEXT( new => @_ );
for my $plugin (@{ $self->class_component_plugins }) {
$plugin->{context} = $self;
Scalar::Util::weaken( $self->{ context } );
}
$self;
}
package Class::Component::Plugin;
sub context { shift->{context} }
1;使い方のサンプルとしては
package OIOI;
use strict;
use warnings;
use Class::Component;
__PACKAGE__->load_components(qw/ PluginSetContext /);
sub hello {
my $self = shift;
print $self->{hello} . "\n";
}
1;package OIOI::Plugin::Hoge;
use strict;
use warnings;
use base 'Class::Component::Plugin';
sub hoge :Method {
my($self, $c) = @_;
$self->context->{hello} = 'hoge';
}
sub uge :Method {
my($self, $c) = @_;
$self->context->{hello} = 'uge';
}
1;use strict;
use warnings;
use OIOI;
my $oioi = OIOI->new({ load_plugins => [ qw / Hoge / ] });
$oioi->call( 'hoge' );
$oioi->hello; # print "hoge\n";
$oioi->call( 'uge' );
$oioi->hello; # print "uge\n";まだまだ、手をつけなきゃいけないところもあるし
とか、他にもいろいろしたいよ!
という要望。