line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::PluginContainer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
365
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: base class for classes holding plugins |
6
|
|
|
|
|
|
|
our $VERSION = '1.4'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
3839
|
use Log::Saftpresse::Log4perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
354
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'plugin_prefix' => ( |
11
|
|
|
|
|
|
|
is => 'rw', isa => 'Str', |
12
|
|
|
|
|
|
|
default => 'Log::Saftpresse::Plugin::', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'plugins' => ( |
16
|
|
|
|
|
|
|
is => 'rw', isa => 'ArrayRef', lazy => 1, |
17
|
|
|
|
|
|
|
default => sub { [] }, |
18
|
|
|
|
|
|
|
traits => [ 'Array' ], |
19
|
|
|
|
|
|
|
handles => { |
20
|
|
|
|
|
|
|
'add_plugin' => 'push', |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub load_plugin { |
25
|
0
|
|
|
0
|
0
|
|
my ( $self, $name, %params )= @_; |
26
|
0
|
0
|
|
|
|
|
if( ! defined $params{'module'} ) { |
27
|
0
|
|
|
|
|
|
die("Parameter module is not defined for Input $name!"); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
my $plugin_class = $self->plugin_prefix.$params{'module'}; |
30
|
0
|
|
|
|
|
|
my $plugin; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$log->info('loading plugin '.$name.' ('.$plugin_class.')...'); |
33
|
0
|
|
|
|
|
|
my $code = "require ".$plugin_class.";"; |
34
|
0
|
|
|
|
|
|
eval $code; ## no critic (ProhibitStringyEval) |
35
|
0
|
0
|
|
|
|
|
if($@) { |
36
|
0
|
|
|
|
|
|
die('could not load plugin '.$plugin_class.': '.$@); |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
eval { |
39
|
0
|
|
|
|
|
|
$plugin = $plugin_class->new( |
40
|
|
|
|
|
|
|
name => $name, |
41
|
|
|
|
|
|
|
%params |
42
|
|
|
|
|
|
|
); |
43
|
0
|
|
|
|
|
|
$plugin->init(); |
44
|
|
|
|
|
|
|
}; |
45
|
0
|
0
|
|
|
|
|
if($@) { |
46
|
0
|
|
|
|
|
|
die('could not initialize plugin '.$plugin_class.': '.$@); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
$self->add_plugin($plugin); |
49
|
0
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub load_config { |
53
|
0
|
|
|
0
|
0
|
|
my ( $self, $config ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->plugins( [] ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
foreach my $plugin ( keys %$config ) { |
58
|
0
|
|
|
|
|
|
$self->load_plugin( $plugin, %{$config->{$plugin}} ); |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_plugin { |
65
|
0
|
|
|
0
|
0
|
|
my ( $self, $name ) = @_; |
66
|
0
|
|
|
|
|
|
my ( $plugin ) = grep { $_->name eq $name } @{$self->plugins}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return( $plugin ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=pod |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=encoding UTF-8 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 NAME |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Log::Saftpresse::PluginContainer - base class for classes holding plugins |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 1.4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software, licensed under: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |