MtPolicyd/Plugin/ClearFields.pm

filter: Statementstmt 100% 37 / 37 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 33.3% 1 / 3 totaltotal 92.3% 48 / 52 CC 7 SCAR 9.9
CC
7
Cov
95%
clear_fields_prefix
4.0
run
3.1
clear_fields
2.0
CRAP 2.7
« MtPolicyd/Plugin/AddScoreHeader.pm ↑ Summary MtPolicyd/Plugin/GeoIPLookup.pm »
1 package Mail::MtPolicyd::Plugin::ClearFields;
2  
3 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '1.11'; # VERSION
7 # ABSTRACT: mtpolicyd plugin to unset session variables
8  
9  
10 2 extends 'Mail::MtPolicyd::Plugin';
11  
12 2 ▶use Mail::MtPolicyd::Plugin::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 has 'fields' => ( is => 'rw', isa => 'Maybe[Str]' );
15 2 has 'fields_prefix' => ( is => 'rw', isa => 'Maybe[Str]' );
16  
17 sub clear_fields {
18 1 ▶ my ( $self, $r ) = @_;
Subroutine clear_fields: called CC=2 SCAR=6.9
Pod undocumented
19 1 my @fields = split(/\s*,\s*/, $self->fields);
20  
21 1 $self->log($r, 'clearing fields '.join(', ', @fields));
22 1 foreach my $field ( @fields ) {
23 1 delete $r->session->{$field};
24 }
25 1 return;
26 }
27  
28 sub clear_fields_prefix {
29 1 ▶ my ( $self, $r ) = @_;
Subroutine clear_fields_prefix: called CC=4 SCAR=13.9
Pod undocumented
30 1 my @prefixes = split(/\s*,\s*/, $self->fields_prefix);
31  
32 1 $self->log($r, 'clearing fields with prefixes: '.join(', ', @prefixes));
33 1 foreach my $prefix ( @prefixes ) {
34 2 foreach my $field ( keys %{$r->session} ) {
35 13 ▶ if( $field !~ /^\Q$prefix\E/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($field =~ /^\Q$prefix\E/) 8 5 13
36 8 next;
37 }
38 5 delete $r->session->{$field};
39 }
40 }
41 1 return;
42 }
43  
44 sub run {
45 1 ▶ my ( $self, $r ) = @_;
Subroutine run: called CC=3 SCAR=11.2
Pod documented
46  
47 1 ▶ if( defined $self->fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->fields) 1 0 1
48 1 $self->clear_fields( $r );
49 }
50 1 ▶ if( defined $self->fields_prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->fields_prefix) 1 0 1
51 1 $self->clear_fields_prefix( $r );
52 }
53  
54 1 return;
55 }
56  
57 2 __PACKAGE__->meta->make_immutable;
58  
59 2 1;
60  
61  
62 __END__
63 =pod
64  
65 =head1 NAME
66  
67 Mail::MtPolicyd::Plugin::ClearFields - mtpolicyd plugin to unset session variables
68  
69 =head1 VERSION
70  
71 version 1.11
72  
73 =head1 DESCRIPTION
74  
75 This plugin could be used to reset some session variables.
76  
77 =head1 PARAMETERS
78  
79 =over
80  
81 =item fields (default: empty)
82  
83 A comma seperated list of session variables to unset.
84  
85 =item fields_prefix (default: empty)
86  
87 A comma seperated list of prefixes.
88 All session variables with this prefixes will be unset.
89  
90 =back
91  
92 =head1 EXAMPLE
93  
94 <Plugin cleanup>
95 module = "ClearFields"
96 fields = "spamhaus-rbl,spamhaus-dbl"
97 </Plugin>
98  
99 Will remove both fields from the session.
100  
101 <Plugin cleanup>
102 module = "ClearFields"
103 fields_prefix = "spamhaus-"
104 </Plugin>
105  
106 Will also remove both fields and everything else starting with "spamhaus-" from the session.
107  
108 =head1 AUTHOR
109  
110 Markus Benning <ich@markusbenning.de>
111  
112 =head1 COPYRIGHT AND LICENSE
113  
114 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
115  
116 This is free software, licensed under:
117  
118 The GNU General Public License, Version 2, June 1991
119  
120 =cut
121  
« MtPolicyd/Plugin/AddScoreHeader.pm ↑ Summary MtPolicyd/Plugin/GeoIPLookup.pm »