line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Auth::Kokolores::Plugins; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.01'; # VERSION |
6
|
|
|
|
|
|
|
# ABSTRACT: class for handling kokolores plugins |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'plugins' => ( |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
isa => 'ArrayRef[Auth::Kokolores::Plugin]', |
11
|
|
|
|
|
|
|
default => sub { [] }, |
12
|
|
|
|
|
|
|
traits => [ 'Array' ], |
13
|
|
|
|
|
|
|
handles => { |
14
|
|
|
|
|
|
|
'add_plugin' => 'push', |
15
|
|
|
|
|
|
|
'all_plugins' => 'elements', |
16
|
|
|
|
|
|
|
'num_plugins' => 'count', |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'plugin_prefix' => ( |
21
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', default => 'Auth::Kokolores::Plugin::', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
25
|
0
|
|
|
0
|
0
|
|
my ( $self, $server ) = @_; |
26
|
0
|
|
|
|
|
|
foreach my $p ( $self->all_plugins ) { |
27
|
0
|
|
|
|
|
|
$server->log(4, 'initializing plugin '.$p->name.'...'); |
28
|
0
|
|
|
|
|
|
$p->init(@_); |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub child_init { |
34
|
0
|
|
|
0
|
0
|
|
my ( $self, $server ) = @_; |
35
|
0
|
|
|
|
|
|
foreach my $p ( $self->all_plugins ) { |
36
|
0
|
|
|
|
|
|
$server->log(4, 'in-child initialization of plugin '.$p->name.'...'); |
37
|
0
|
|
|
|
|
|
$p->child_init(@_); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub shutdown { |
43
|
0
|
|
|
0
|
0
|
|
my ( $self, $server ) = @_; |
44
|
0
|
|
|
|
|
|
foreach my $p ( $self->all_plugins ) { |
45
|
0
|
|
|
|
|
|
$server->log(4, 'shuting down plugin '.$p->name.'...'); |
46
|
0
|
|
|
|
|
|
$p->shutdown(@_); |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub load_plugin { |
52
|
0
|
|
|
0
|
0
|
|
my ( $self, $plugin_name, $params ) = @_; |
53
|
0
|
0
|
|
|
|
|
if( ! defined $params->{'module'} ) { |
54
|
0
|
|
|
|
|
|
die('no module defined for plugin '.$plugin_name.'!'); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
my $module = $params->{'module'}; |
57
|
0
|
|
|
|
|
|
my $plugin_class = $self->plugin_prefix.$module; |
58
|
0
|
|
|
|
|
|
my $plugin; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $code = "require ".$plugin_class.";"; |
61
|
0
|
|
|
|
|
|
eval $code; ## no critic (ProhibitStringyEval) |
62
|
0
|
0
|
|
|
|
|
if($@) { |
63
|
0
|
|
|
|
|
|
die('could not load module '.$module.' for plugin '.$plugin_name.': '.$@); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
eval { |
67
|
0
|
|
|
|
|
|
$plugin = $plugin_class->new( |
68
|
|
|
|
|
|
|
name => $plugin_name, |
69
|
|
|
|
|
|
|
%$params, |
70
|
|
|
|
|
|
|
); |
71
|
0
|
|
|
|
|
|
$plugin->init(); |
72
|
|
|
|
|
|
|
}; |
73
|
0
|
0
|
|
|
|
|
if($@) { |
74
|
0
|
|
|
|
|
|
die('could not initialize plugin '.$plugin_name.': '.$@); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
$self->add_plugin($plugin); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub new_from_config { |
82
|
0
|
|
|
0
|
0
|
|
my ( $class, $server, $config ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $self = $class->new(); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if( ! defined $config ) { |
87
|
0
|
|
|
|
|
|
return( $self ); |
88
|
|
|
|
|
|
|
} |
89
|
0
|
0
|
|
|
|
|
if( ref($config) ne 'HASH' ) { |
90
|
0
|
|
|
|
|
|
die('config must be an hashref!'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
foreach my $plugin_name ( keys %{$config} ) { |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$self->load_plugin( |
95
|
|
|
|
|
|
|
$plugin_name, { |
96
|
|
|
|
|
|
|
server => $server, |
97
|
0
|
|
|
|
|
|
%{$config->{$plugin_name}}, |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
$server->log(2, 'loaded '.$self->num_plugins.' plugins...'); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
return $self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=pod |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=encoding UTF-8 |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Auth::Kokolores::Plugins - class for handling kokolores plugins |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 VERSION |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
version 1.01 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Markus Benning <ich@markusbenning.de>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software, licensed under: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |