| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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 | ||||||||||