Config-Yak
view release on metacpan or search on metacpan
lib/Config/Yak/OrderedPlugins.pm view on Meta::CPAN
package Config::Yak::OrderedPlugins;
{
$Config::Yak::OrderedPlugins::VERSION = '0.23';
}
BEGIN {
$Config::Yak::OrderedPlugins::AUTHORITY = 'cpan:TEX';
}
# ABSTRACT: a role to provide handling of ordered plugins
use 5.010_000;
use mro 'c3';
use feature ':5.10';
use Moose::Role;
use namespace::autoclean;
# use IO::Handle;
# use autodie;
# use MooseX::Params::Validate;
# use Carp;
use English qw( -no_match_vars );
use Try::Tiny;
use Module::Pluggable::Object;
# extends ...
# has ...
has '_finder' => (
'is' => 'rw',
'isa' => 'Module::Pluggable::Object',
'lazy' => 1,
'builder' => '_init_finder',
'accessor' => 'finder',
);
has '_plugins' => (
'is' => 'rw',
'isa' => 'ArrayRef',
'lazy' => 1,
'builder' => '_init_plugins',
'accessor' => 'plugins',
);
has '_finder_search_path' => (
'is' => 'rw',
'isa' => 'ArrayRef[Str]',
'lazy' => 1,
'builder' => '_init_finder_search_path',
);
# with ...
with qw(Config::Yak::RequiredConfig Log::Tree::RequiredLogger);
# initializers ...
sub _init_finder_search_path {
my $self = shift;
return [$self->_plugin_base_class()];
}
sub _init_finder {
my $self = shift;
# The finder is the class that finds our available plugins
my $Finder = Module::Pluggable::Object::->new( 'search_path' => $self->_finder_search_path() );
return $Finder;
} ## end sub _init_finder
sub _init_plugins {
my $self = shift;
# Allow the plugins to be sorted by prio in the config with the Priority
# key in each plugin section. Why priorities? It may make sense or even
# be a strict requirement to run some plugins before or after
# another one.
my $order_ref = {};
PLUGIN: foreach my $plugin_name ( $self->finder()->plugins() ) {
## no critic (ProhibitStringyEval)
my $eval_status = eval "require $plugin_name;";
## use critic
if ( !$eval_status ) {
$self->logger()->log( message => 'Failed to require ' . $plugin_name . ': ' . $EVAL_ERROR, level => 'warning', );
( run in 0.778 second using v1.01-cache-2.11-cpan-d8267643d1d )