MooseX::Role::Pluggable - add plugins to your Moose classes
version 0.07
package MyMoose; use Moose; with 'MooseX::Role::Pluggable'; my $moose = MyMoose->new({ plugins => [ 'Antlers' , 'Tail' , '+After::Market::GroundEffectsPackage' ] , # other args here }); or, if you need to pass arguments to a plugin module, you can do that by using a hashref in the plugin list: my $moose = MyMoose->new({ plugins => [ { 'Antlers' => { long => 1, } }, { 'Tail' => { short => 1, } }, '+After::Market::GroundEffectsPackage' => {}, ] }); foreach my $plugin ( @{ $moose->plugin_list } ) { if ( $plugin->can( 'some_method' )) { $plugin->some_method(); } } # call a method in a particular plugin directly # (plugin_hash() returns a hash ref of 'plugin_name => plugin') $moose->plugin_hash->{Antlers}->gore( $other_moose ); # plugins are indexed by the name that was used in the original 'plugins' list $moose->plugin_hash->{After::Market::GroundEffectsPackage}->light_up(); # see the documentation for MooseX::Role::Pluggable::Plugin for info on # how to write plugins...
This is a role that allows your class to consume an arbitrary set of plugin modules and then access those plugins and use them to do stuff.
Plugins are loaded based on the list of plugin names in the 'plugins' attribute. Names that start with a '+' are used as the full name to load; names that don't start with a leading '+' are assumed to be in a 'Plugins' namespace under your class name. (E.g., if your app is 'MyApp', plugins will be loaded from 'MyApp::Plugin').
NOTE: Plugins are lazily loaded -- that is, no plugins will be loaded until either the 'plugin_list' or 'plugin_hash' methods are called. If you want to force plugins to load at object instantiation time, your best bet is to call one of those method right after you call 'new()'.
Plugin classes should consume the 'MooseX::Role::Pluggable::Plugin' role; see the documentation for that module for more information.
Returns a hashref with a mapping of 'plugin_name' to the actual plugin object.
Returns an arrayref of loaded plugin objects. The arrayref will have the same order as the plugins array ref passed in during object creation.
Looks for a method named $method_name in each plugin in the plugin list. If a method of given name is found, it will be run. (N.b., this is essentially the foreach loop from the "SYNOPSIS".)
foreach
John SJ Anderson, genehack@genehack.org
genehack@genehack.org
Sean Maguire smaguire@talktalkplc.com
smaguire@talktalkplc.com
MooseX::Role::Pluggable::Plugin, MooseX::Object::Pluggable, Object::Pluggable
Copyright 2014, John SJ Anderson
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
John SJ Anderson <john@genehack.org>
This software is copyright (c) 2020 by John SJ Anderson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::Role::Pluggable, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Role::Pluggable
CPAN shell
perl -MCPAN -e shell install MooseX::Role::Pluggable
For more information on module installation, please visit the detailed CPAN module installation guide.