line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::MtPolicyd::Plugin::Role::ConfigurableFields; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
4614
|
use strict; # make critic happy |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
122
|
|
4
|
4
|
|
|
4
|
|
1586
|
use MooseX::Role::Parameterized; |
|
4
|
|
|
|
|
117730
|
|
|
4
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
84347
|
use Moose::Util::TypeConstraints; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
42
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.23'; # VERSION |
9
|
|
|
|
|
|
|
# ABSTRACT: role for plugins using configurable fields |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
parameter fields => ( |
12
|
|
|
|
|
|
|
isa => 'HashRef[HashRef]', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
role { |
17
|
|
|
|
|
|
|
my $p = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
foreach my $attr ( keys %{$p->fields} ) { |
20
|
|
|
|
|
|
|
my $value_isa = $p->fields->{$attr}->{'value_isa'}; |
21
|
|
|
|
|
|
|
delete $p->fields->{$attr}->{'value_isa'}; |
22
|
|
|
|
|
|
|
has $attr.'_field' => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
25
|
|
|
|
|
|
|
%{$p->fields->{$attr}}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
method 'get_'.$attr.'_value' => sub { |
28
|
0
|
|
|
0
|
|
0
|
my ( $self, $r ) = @_; |
|
10
|
|
|
10
|
|
491
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
6
|
|
|
|
29
|
0
|
|
|
|
|
0
|
return $self->get_configurable_field_value( $r, $attr, |
|
10
|
|
|
|
|
58
|
|
30
|
|
|
|
|
|
|
$value_isa ); |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub get_configurable_field_value { |
36
|
10
|
|
|
10
|
0
|
48
|
my ( $self, $r, $name, $type ) = @_; |
37
|
10
|
|
|
|
|
28
|
my $conf_field = $name.'_field'; |
38
|
|
|
|
|
|
|
|
39
|
10
|
|
|
|
|
633
|
my $request_field = $self->$conf_field; |
40
|
10
|
50
|
33
|
|
|
77
|
if( ! defined $request_field || $request_field eq '' ) { |
41
|
0
|
|
|
|
|
0
|
$self->log( $r, 'no request field configured in '.$conf_field ); |
42
|
0
|
|
|
|
|
0
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
10
|
|
|
|
|
559
|
my $value = $r->attr( $request_field ); |
46
|
10
|
100
|
66
|
|
|
76
|
if( ! defined $value || $value eq '' ) { |
47
|
1
|
|
|
|
|
11
|
$self->log( $r, 'value of field '.$request_field. |
48
|
|
|
|
|
|
|
' not defined or empty' ); |
49
|
1
|
|
|
|
|
16
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
9
|
50
|
|
|
|
28
|
if( defined $type ) { |
53
|
9
|
|
|
|
|
58
|
my $constraint = find_type_constraint( $type ); |
54
|
9
|
|
|
|
|
1239
|
my $err = $constraint->validate( $value ); |
55
|
9
|
100
|
|
|
|
1550
|
if( defined $err ) { |
56
|
1
|
|
|
|
|
15
|
$self->log( $r, 'value of field '.$request_field. |
57
|
|
|
|
|
|
|
' failed validation for '.$type.': '.$err ); |
58
|
1
|
|
|
|
|
12
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
8
|
|
|
|
|
52
|
return $value; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=encoding UTF-8 |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Mail::MtPolicyd::Plugin::Role::ConfigurableFields - role for plugins using configurable fields |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 1.23 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This is free software, licensed under: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |