Saftpresse/PluginContainer.pm

filter: Statementstmt 25.6% 10 / 39 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 2 / 6 Podpod 0.0% 0 / 3 totaltotal 22.2% 12 / 54 SCAR 28.2
CC
5
Cov
22%
load_plugin
20.0
load_config
6.0
__ANON__
2.0
CRAP 16.8
« Saftpresse/Analyzer.pm ↑ Summary Saftpresse/Log4perl.pm »
1 package Log::Saftpresse::PluginContainer;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: base class for classes holding plugins
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 ▶use Log::Saftpresse::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 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 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 1 traits => [ 'Array' ],
19 handles => {
20 'add_plugin' => 'push',
21 },
22 );
23  
24 sub load_plugin {
25 0 ▶ my ( $self, $name, %params )= @_;
Subroutine load_plugin: not called CC=4 SCAR=30.0
Pod undocumented
26 0 ▶ if( ! defined $params{'module'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"module"}) 0 0 0
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 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
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 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
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 ▶ my ( $self, $config ) = @_;
Subroutine load_config: not called CC=2 SCAR=17.9
Pod undocumented
54  
55 0 $self->plugins( [] );
56  
57 0 foreach my $plugin ( keys %$config ) {
58 0 $self->load_plugin( $plugin, %{$config->{$plugin}} );
59 }
60  
61 0 return;
62 }
63  
64 sub get_plugin {
65 0 ▶ my ( $self, $name ) = @_;
Subroutine get_plugin: not called CC=1 SCAR=6.9
Pod undocumented
66 0 my ( $plugin ) = grep { $_->name eq $name } @{$self->plugins};
67 0 return( $plugin );
68 }
69  
70 1 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.5
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
« Saftpresse/Analyzer.pm ↑ Summary Saftpresse/Log4perl.pm »