line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Yak::NamedPlugins; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Config::Yak::NamedPlugins::VERSION = '0.23'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
1
|
|
|
1
|
|
4379
|
$Config::Yak::NamedPlugins::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: a role to provide handling of named plugins |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
30
|
use 5.010_000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
11
|
1
|
|
|
1
|
|
6
|
use mro 'c3'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
30
|
use feature ':5.10'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
117
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
460
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use namespace::autoclean; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# use IO::Handle; |
18
|
|
|
|
|
|
|
# use autodie; |
19
|
|
|
|
|
|
|
# use MooseX::Params::Validate; |
20
|
|
|
|
|
|
|
# use Carp; |
21
|
|
|
|
|
|
|
use English qw( -no_match_vars ); |
22
|
|
|
|
|
|
|
use Try::Tiny; |
23
|
|
|
|
|
|
|
use Scalar::Util qw(); |
24
|
|
|
|
|
|
|
use Module::Pluggable::Object; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# extends ... |
27
|
|
|
|
|
|
|
# has ... |
28
|
|
|
|
|
|
|
has '_finder' => ( |
29
|
|
|
|
|
|
|
'is' => 'rw', |
30
|
|
|
|
|
|
|
'isa' => 'Module::Pluggable::Object', |
31
|
|
|
|
|
|
|
'lazy' => 1, |
32
|
|
|
|
|
|
|
'builder' => '_init_finder', |
33
|
|
|
|
|
|
|
'accessor' => 'finder', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has '_plugins' => ( |
37
|
|
|
|
|
|
|
'is' => 'rw', |
38
|
|
|
|
|
|
|
'isa' => 'HashRef', |
39
|
|
|
|
|
|
|
'lazy' => 1, |
40
|
|
|
|
|
|
|
'builder' => '_init_plugins', |
41
|
|
|
|
|
|
|
'accessor' => 'plugins', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has '_finder_search_path' => ( |
45
|
|
|
|
|
|
|
'is' => 'rw', |
46
|
|
|
|
|
|
|
'isa' => 'ArrayRef[Str]', |
47
|
|
|
|
|
|
|
'lazy' => 1, |
48
|
|
|
|
|
|
|
'builder' => '_init_finder_search_path', |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# with ... |
52
|
|
|
|
|
|
|
with qw(Config::Yak::RequiredConfig Log::Tree::RequiredLogger); |
53
|
|
|
|
|
|
|
# initializers ... |
54
|
|
|
|
|
|
|
sub _init_finder_search_path { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return [$self->_plugin_base_class()]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _init_finder { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# The finder is the class that finds our available plugins |
64
|
|
|
|
|
|
|
my $Finder = Module::Pluggable::Object::->new( 'search_path' => $self->_finder_search_path() ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $Finder; |
67
|
|
|
|
|
|
|
} ## end sub _init_finder |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _init_plugins { |
70
|
|
|
|
|
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $plugin_ref = {}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
PLUGIN: foreach my $plugin_name ( $self->finder()->plugins() ) { |
75
|
|
|
|
|
|
|
## no critic (ProhibitStringyEval) |
76
|
|
|
|
|
|
|
my $eval_status = eval "require $plugin_name;"; |
77
|
|
|
|
|
|
|
## use critic |
78
|
|
|
|
|
|
|
if ( !$eval_status ) { |
79
|
|
|
|
|
|
|
$self->logger()->log( message => 'Failed to require ' . $plugin_name . ': ' . $EVAL_ERROR, level => 'warning', ); |
80
|
|
|
|
|
|
|
next; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
my $arg_ref = $self->config()->get($plugin_name); |
83
|
|
|
|
|
|
|
$arg_ref->{'logger'} = $self->logger(); |
84
|
|
|
|
|
|
|
$arg_ref->{'config'} = $self->config(); |
85
|
|
|
|
|
|
|
$arg_ref->{'parent'} = $self; |
86
|
|
|
|
|
|
|
Scalar::Util::weaken( $arg_ref->{'parent'} ); |
87
|
|
|
|
|
|
|
if ( $arg_ref->{'disabled'} ) { |
88
|
|
|
|
|
|
|
$self->logger()->log( message => 'Skipping disabled plugin: ' . $plugin_name, level => 'debug', ); |
89
|
|
|
|
|
|
|
next PLUGIN; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
try { |
92
|
|
|
|
|
|
|
my $Plugin = $plugin_name->new($arg_ref); |
93
|
|
|
|
|
|
|
my $prio = $Plugin->priority(); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# disabled/abstract plugins will set a prio of 0 |
96
|
|
|
|
|
|
|
if ( $prio > 0 ) { |
97
|
|
|
|
|
|
|
$plugin_ref->{$plugin_name} = $Plugin; |
98
|
|
|
|
|
|
|
$self->logger()->log( message => 'Loaded plugin '.ref($Plugin).' w/ name '.$plugin_name, level => 'debug', ); |
99
|
|
|
|
|
|
|
} else { |
100
|
|
|
|
|
|
|
$self->logger()->log( message => 'Skipped loaded plugin '.ref($Plugin).' w/ name '.$plugin_name, level => 'debug', ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} ## end try |
103
|
|
|
|
|
|
|
catch { |
104
|
|
|
|
|
|
|
$self->logger()->log( message => 'Failed to initialize plugin ' . $plugin_name . ' w/ error: ' . $_, level => 'warning', ); |
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
} ## end foreach my $plugin_name ( $self...) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return $plugin_ref; |
109
|
|
|
|
|
|
|
} ## end sub _init_plugins |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# requires ... |
112
|
|
|
|
|
|
|
requires qw(_plugin_base_class); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# your code here ... |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
no Moose::Role; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=encoding utf-8 |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 NAME |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Config::Yak::NamedPlugins - a role to provide handling of named plugins |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SYNOPSIS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
use Moose; |
133
|
|
|
|
|
|
|
with 'Config::Yak::NamedPlugins'; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This Moose role provides an plugin hanlder for named plugins. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Upon access to the plugins() method this role will search |
140
|
|
|
|
|
|
|
for all plugins within the search path defined by _plugin_base_class(). |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
It will also require an Config::Yak instance and a Log::Tree instance. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 NAME |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Config::Yak::NamedPlugins - This role provides an handler for named plugins. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 AUTHOR |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Dominik Schulz <dominik.schulz@gauner.org> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Dominik Schulz. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
157
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |