Class::Component - pluggable component framework
base class
package MyClass; use strict; use warnings; use Class::Component; __PACKAGE__->load_component(qw/ Autocall::InjectMethod /); __PACKAGE__->load_plugins(qw/ Default /);
application code
use strict; use warnings; use MyClass; my $obj = MyClass->new({ load_plugins => [qw/ Hello /] }); $obj->hello; # autocall $obj->run_hook( hello => $args );
Class::Component is pluggable component framework. The compatibilities such as dump and load such as YAML are good.
constructor
__PACKAGE__->load_components(qw/ Sample /);
The candidate is the order of MyClass::Component::Sample and Class::Component::Sample. It looks for the module in order succeeded to by @ISA. It is used to remove + when there is + in the head.
__PACKAGE__->load_plugins(qw/ Default /);
The candidate is the MyClass::Plugin::Default. It looks for the module in order succeeded to by @ISA. It is used to remove + when there is + in the head.
$obj->register_method( 'method name' => 'MyClass::Plugin::PluginName' );
Method attribute is usually used and set. See Also Class::Component::Plugin.
$obj->register_hook( 'hook name' => { plugin => 'MyClass::Plugin::PluginName', method => 'hook method name' } );
Hook attribute is usually used and set. See Also Class::Component::Plugin.
$obj->remove_method( 'method name' => 'MyClass::Plugin::PluginName' );
$obj->remove_hook( 'hook name' => { plugin => 'MyClass::Plugin::PluginName', method => 'hook method name' } );
$obj->call('plugin method name' => @args) $obj->call('plugin method name' => %args)
$obj->run_hook('hook name' => $args)
$self->NEXT('methods name', @args);
It is behavior near maybe::next::method of Class::C3.
Given an (possibly) unqualified plugin name (say, "Foo"), resolves it into a fully qualified module name (say, "MyApp::Plugin::Foo")
use Class::Component reload_plugin => 1;
or
MyClass->class_component_reinitialize( reload_plugin => 1 );
Plugin/Component of the object made with YAML::Load etc. is done and require is done automatically.
SEE ALSO Class::Component::Attribute::Method and Class::Component::Attribute::Hook test code in ./t directory. (MyClass::Attribute::Test and MyClass::Plugin::ExtAttribute)
It is an outline of Components that the bundle is done in Class::Components::Components or less.
plugin can be added, lost from new and the object method, and some speeds are improved.
package MyClass; use base 'Class::Component'; __PACKAGE__->load_components(qw/ DisableDynamicPlugin /); package main; MyClass->load_plugins(qw/ Test /); # is ok! my $obj = MyClass->new; $obj->load_plugins(qw/ NoNoNo /); # not loaded my $obj2 = MyClass->new({ load_plugins => qw/ OOPS / }); # not loaded
It keeps accessible with method defined by register_method. using AUTOLOAD.
package MyClass::Plugin::Test; use base 'Class::Component::Plugin'; sub test :Method { print "plugin load ok" } package MyClass; use base 'Class::Component'; __PACKAGE__->load_components(qw/ Autocall::Autoload /); package main; MyClass->load_plugins(qw/ Test /); my $obj = MyClass->new; $obj->test; # plugin load ok
It is the same as Autocall::Autoload. The method is actually added.
The method is added in the form of singleton method. It is not influenced by other objects. It is not possible to use it at the same time as DisableDynamicPlugin.
package MyClass::Plugin::Test; use base 'Class::Component::Plugin'; sub test :Method { print "plugin load ok" } package MyClass; use base 'Class::Component'; __PACKAGE__->load_components(qw/ Autocall::Autoload /); package main; MyClass->; my $obj = MyClass->new({ load_plugins => [qw/ Test /] }); $obj->test; # plugin load ok my $obj2 = MyClass->new; $obj2->test; # died
AutoloadPlugin is Plagger->autoload_plugin like
$c->autoload_plugins({ module => 'Hello' }); $c->autoload_plugins({ module => 'Hello', config => {} }); $c->autoload_plugins({ module => '+Foo::Plugin::Hello' }); $c->autoload_plugins({ module => '+Foo::Plugin::Hello', config => {} });
the under case is same to load_pugins method
$c->autoload_plugins('Hello'); $c->autoload_plugins('+Foo::Plugin::Hello');
The Plaggerize is extend your module like from Plagger component.
see. Class::Component::Component::Plaggerize
Kazuhiro Osawa <ko@yappo.ne.jp>
Tokuhiro Matsuno
Class::Component::Plugin
HTTP::MobileAttribute, Number::Object, App::MadEye
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Component, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Component
CPAN shell
perl -MCPAN -e shell install Class::Component
For more information on module installation, please visit the detailed CPAN module installation guide.