line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::PluginChain; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
23
|
use Moose; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
30
|
|
4
|
6
|
|
|
6
|
|
24622
|
use namespace::autoclean; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
43
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.01'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: class for a VirtualHost instance |
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
1925
|
use Mail::MtPolicyd::Profiler; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
201
|
|
10
|
6
|
|
|
6
|
|
2434
|
use Mail::MtPolicyd::Result; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
3351
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'plugins' => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef[Mail::MtPolicyd::Plugin]', |
15
|
|
|
|
|
|
|
default => sub { [] }, |
16
|
|
|
|
|
|
|
traits => [ 'Array' ], |
17
|
|
|
|
|
|
|
handles => { |
18
|
|
|
|
|
|
|
'add_plugin' => 'push', |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'plugin_prefix' => ( |
23
|
|
|
|
|
|
|
is => 'ro', isa => 'Str', default => 'Mail::MtPolicyd::Plugin::', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'vhost_name' => ( is => 'rw', isa => 'Maybe[Str]' ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub run { |
29
|
2
|
|
|
2
|
0
|
111
|
my ( $self, $r ) = @_; |
30
|
2
|
|
|
|
|
73
|
my $result = Mail::MtPolicyd::Result->new; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
4
|
foreach my $plugin ( @{$self->plugins} ) { |
|
2
|
|
|
|
|
87
|
|
33
|
2
|
|
|
|
|
3
|
my $abort = 0; |
34
|
2
|
|
|
|
|
70
|
Mail::MtPolicyd::Profiler->new_timer('plugin '.$plugin->name); |
35
|
2
|
|
|
|
|
3
|
my @plugin_results; |
36
|
2
|
|
|
|
|
2
|
eval { @plugin_results = $plugin->run($r); }; |
|
2
|
|
|
|
|
8
|
|
37
|
2
|
|
|
|
|
5
|
my $e = $@; |
38
|
2
|
50
|
|
|
|
5
|
if( $e ) { |
39
|
0
|
|
|
|
|
0
|
my $msg = 'plugin '.$plugin->name.' failed: '.$e; |
40
|
0
|
0
|
0
|
|
|
0
|
if( ! defined $plugin->on_error || $plugin->on_error ne 'continue' ) { |
41
|
0
|
|
|
|
|
0
|
die($msg); |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
0
|
$r->log(0, $msg); |
44
|
|
|
|
|
|
|
} |
45
|
2
|
|
|
|
|
8
|
Mail::MtPolicyd::Profiler->stop_current_timer; |
46
|
2
|
50
|
|
|
|
5
|
if( scalar @plugin_results ) { |
47
|
2
|
|
|
|
|
60
|
$result->last_match( $plugin->name ); |
48
|
|
|
|
|
|
|
} |
49
|
2
|
|
|
|
|
6
|
foreach my $plugin_result ( @plugin_results ) { |
50
|
2
|
|
|
|
|
86
|
$result->add_plugin_result($plugin_result); |
51
|
2
|
50
|
|
|
|
73
|
if( $plugin_result->abort ) { |
52
|
2
|
|
|
|
|
5
|
$abort = 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
2
|
50
|
|
|
|
10
|
if( $abort ) { last; } |
|
2
|
|
|
|
|
5
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
11
|
return $result; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub cron { |
62
|
2
|
|
|
2
|
0
|
2
|
my $self = shift; |
63
|
2
|
|
|
|
|
2
|
my $server = shift; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
2
|
foreach my $plugin ( @{$self->plugins} ) { |
|
2
|
|
|
|
|
50
|
|
66
|
2
|
|
|
|
|
51
|
$server->log(3, 'running cron for plugin '.$plugin->name); |
67
|
2
|
|
|
|
|
11
|
eval { $plugin->cron( $server, @_ ); }; |
|
2
|
|
|
|
|
6
|
|
68
|
2
|
|
|
|
|
23
|
my $e = $@; |
69
|
2
|
100
|
|
|
|
6
|
if( $e ) { |
70
|
1
|
|
|
|
|
25
|
$server->log(0, 'plugin '.$plugin->name.' failed in cron: '.$e ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
9
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub load_plugin { |
77
|
2
|
|
|
2
|
0
|
2
|
my ( $self, $plugin_name, $params ) = @_; |
78
|
2
|
50
|
|
|
|
7
|
if( ! defined $params->{'module'} ) { |
79
|
0
|
|
|
|
|
0
|
die('no module defined for plugin '.$plugin_name.'!'); |
80
|
|
|
|
|
|
|
} |
81
|
2
|
|
|
|
|
4
|
my $module = $params->{'module'}; |
82
|
2
|
|
|
|
|
56
|
my $plugin_class = $self->plugin_prefix.$module; |
83
|
2
|
|
|
|
|
2
|
my $plugin; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
11
|
my $code = "require ".$plugin_class.";"; |
86
|
2
|
|
|
|
|
103
|
eval $code; ## no critic (ProhibitStringyEval) |
87
|
2
|
50
|
|
|
|
11
|
if($@) { |
88
|
0
|
|
|
|
|
0
|
die('could not load module '.$module.' for plugin '.$plugin_name.': '.$@); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
3
|
eval { |
92
|
2
|
|
|
|
|
61
|
$plugin = $plugin_class->new( |
93
|
|
|
|
|
|
|
name => $plugin_name, |
94
|
|
|
|
|
|
|
vhost_name => $self->vhost_name, |
95
|
|
|
|
|
|
|
%$params, |
96
|
|
|
|
|
|
|
); |
97
|
2
|
|
|
|
|
1037
|
$plugin->init(); |
98
|
|
|
|
|
|
|
}; |
99
|
2
|
50
|
|
|
|
6
|
if($@) { |
100
|
0
|
|
|
|
|
0
|
die('could not initialize plugin '.$plugin_name.': '.$@); |
101
|
|
|
|
|
|
|
} |
102
|
2
|
|
|
|
|
74
|
$self->add_plugin($plugin); |
103
|
2
|
|
|
|
|
5
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new_from_config { |
107
|
2
|
|
|
2
|
0
|
4
|
my ( $class, $vhost_name, $config ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
|
|
56
|
my $self = $class->new( vhost_name => $vhost_name ); |
110
|
|
|
|
|
|
|
|
111
|
2
|
50
|
|
|
|
6
|
if( ! defined $config ) { |
112
|
0
|
|
|
|
|
0
|
return( $self ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
2
|
50
|
|
|
|
6
|
if( ref($config) ne 'HASH' ) { |
116
|
0
|
|
|
|
|
0
|
die('config must be an hashref!'); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
2
|
foreach my $plugin_name ( keys %{$config} ) { |
|
2
|
|
|
|
|
7
|
|
120
|
|
|
|
|
|
|
$self->load_plugin($plugin_name, |
121
|
2
|
|
|
|
|
9
|
$config->{$plugin_name} ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
58
|
return $self; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=pod |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=encoding UTF-8 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 NAME |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Mail::MtPolicyd::PluginChain - class for a VirtualHost instance |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 VERSION |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
version 2.01 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is free software, licensed under: |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |