line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::PluginChain; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
30
|
use Moose; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
39
|
|
4
|
6
|
|
|
6
|
|
37634
|
use namespace::autoclean; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: class for a VirtualHost instance |
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
2785
|
use Mail::MtPolicyd::Profiler; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
237
|
|
10
|
6
|
|
|
6
|
|
4020
|
use Mail::MtPolicyd::Result; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
5217
|
|
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
|
152
|
my ( $self, $r ) = @_; |
30
|
2
|
|
|
|
|
97
|
my $result = Mail::MtPolicyd::Result->new; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
3
|
foreach my $plugin ( @{$self->plugins} ) { |
|
2
|
|
|
|
|
82
|
|
33
|
2
|
|
|
|
|
5
|
my $abort = 0; |
34
|
2
|
|
|
|
|
83
|
Mail::MtPolicyd::Profiler->new_timer('plugin '.$plugin->name); |
35
|
2
|
|
|
|
|
4
|
my @plugin_results; |
36
|
2
|
|
|
|
|
5
|
eval { @plugin_results = $plugin->run($r); }; |
|
2
|
|
|
|
|
16
|
|
37
|
2
|
|
|
|
|
6
|
my $e = $@; |
38
|
2
|
50
|
|
|
|
12
|
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
|
|
|
|
|
11
|
Mail::MtPolicyd::Profiler->stop_current_timer; |
46
|
2
|
50
|
|
|
|
8
|
if( scalar @plugin_results ) { |
47
|
2
|
|
|
|
|
76
|
$result->last_match( $plugin->name ); |
48
|
|
|
|
|
|
|
} |
49
|
2
|
|
|
|
|
16
|
foreach my $plugin_result ( @plugin_results ) { |
50
|
2
|
|
|
|
|
156
|
$result->add_plugin_result($plugin_result); |
51
|
2
|
50
|
|
|
|
87
|
if( $plugin_result->abort ) { |
52
|
2
|
|
|
|
|
7
|
$abort = 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
2
|
50
|
|
|
|
7
|
if( $abort ) { last; } |
|
2
|
|
|
|
|
6
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
10
|
return $result; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub cron { |
62
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
63
|
2
|
|
|
|
|
3
|
my $server = shift; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
3
|
foreach my $plugin ( @{$self->plugins} ) { |
|
2
|
|
|
|
|
175
|
|
66
|
2
|
|
|
|
|
74
|
$server->log(3, 'running cron for plugin '.$plugin->name); |
67
|
2
|
|
|
|
|
16
|
eval { $plugin->cron( $server, @_ ); }; |
|
2
|
|
|
|
|
8
|
|
68
|
2
|
|
|
|
|
34
|
my $e = $@; |
69
|
2
|
100
|
|
|
|
7
|
if( $e ) { |
70
|
1
|
|
|
|
|
37
|
$server->log(0, 'plugin '.$plugin->name.' failed in cron: '.$e ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
2
|
|
|
|
|
13
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub load_plugin { |
77
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $plugin_name, $params ) = @_; |
78
|
2
|
50
|
|
|
|
9
|
if( ! defined $params->{'module'} ) { |
79
|
0
|
|
|
|
|
0
|
die('no module defined for plugin '.$plugin_name.'!'); |
80
|
|
|
|
|
|
|
} |
81
|
2
|
|
|
|
|
6
|
my $module = $params->{'module'}; |
82
|
2
|
|
|
|
|
82
|
my $plugin_class = $self->plugin_prefix.$module; |
83
|
2
|
|
|
|
|
6
|
my $plugin; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
8
|
my $code = "require ".$plugin_class.";"; |
86
|
2
|
|
|
|
|
144
|
eval $code; ## no critic (ProhibitStringyEval) |
87
|
2
|
50
|
|
|
|
16
|
if($@) { |
88
|
0
|
|
|
|
|
0
|
die('could not load module '.$module.' for plugin '.$plugin_name.': '.$@); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
5
|
eval { |
92
|
2
|
|
|
|
|
84
|
$plugin = $plugin_class->new( |
93
|
|
|
|
|
|
|
name => $plugin_name, |
94
|
|
|
|
|
|
|
vhost_name => $self->vhost_name, |
95
|
|
|
|
|
|
|
%$params, |
96
|
|
|
|
|
|
|
); |
97
|
2
|
|
|
|
|
1459
|
$plugin->init(); |
98
|
|
|
|
|
|
|
}; |
99
|
2
|
50
|
|
|
|
8
|
if($@) { |
100
|
0
|
|
|
|
|
0
|
die('could not initialize plugin '.$plugin_name.': '.$@); |
101
|
|
|
|
|
|
|
} |
102
|
2
|
|
|
|
|
107
|
$self->add_plugin($plugin); |
103
|
2
|
|
|
|
|
7
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new_from_config { |
107
|
2
|
|
|
2
|
0
|
6
|
my ( $class, $vhost_name, $config ) = @_; |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
|
|
85
|
my $self = $class->new( vhost_name => $vhost_name ); |
110
|
|
|
|
|
|
|
|
111
|
2
|
50
|
|
|
|
8
|
if( ! defined $config ) { |
112
|
0
|
|
|
|
|
0
|
return( $self ); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
2
|
50
|
|
|
|
10
|
if( ref($config) ne 'HASH' ) { |
116
|
0
|
|
|
|
|
0
|
die('config must be an hashref!'); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
4
|
foreach my $plugin_name ( keys %{$config} ) { |
|
2
|
|
|
|
|
8
|
|
120
|
|
|
|
|
|
|
$self->load_plugin($plugin_name, |
121
|
2
|
|
|
|
|
12
|
$config->{$plugin_name} ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
87
|
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 1.23 |
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 |