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