SPF/Mod/Redirect.pm

filter: Statementstmt 70.4% 31 / 44 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 66.6% 2 / 3 totaltotal 66.6% 42 / 63 CC 3 SCAR 12.5
CC
3
Cov
65%
process
12.0
parse_params
2.0
params
2.0
CRAP 3.5
« SPF/Mech/A.pm ↑ Summary SPF/Result.pm »
1 #
2 # Mail::SPF::Mod::Redirect
3 # SPF record "redirect" modifier class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Redirect.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mod::Redirect;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mod::Redirect - SPF record C<redirect> modifier class
16  
17 =head1 VERSION
18  
19 version 3.20261105
20  
21 =cut
22  
23 5 our $VERSION = '3.20261105'; # VERSION
24  
25 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 5 ▶use Mail::SPF::Mod;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use base 'Mail::SPF::GlobalMod';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 5 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 5 ▶use constant name => 'redirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 5 ▶use constant name_pattern => qr/${\name}/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 5 ▶use constant precedence => 0.8;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 =head1 DESCRIPTION
40  
41 An object of class B<Mail::SPF::Mod::Redirect> represents an SPF record
42 modifier of type C<redirect>.
43  
44 =head2 Constructors
45  
46 The following constructors are provided:
47  
48 =over
49  
50 =item B<new(%options)>: returns I<Mail::SPF::Mod::Redirect>
51  
52 Creates a new SPF record C<redirect> modifier object.
53  
54 %options is a list of key/value pairs representing any of the following
55 options:
56  
57 =over
58  
59 =item B<domain_spec>
60  
61 See L<Mail::SPF::Mod/new>.
62  
63 =back
64  
65 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mod::Redirect>;
66 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMod>
67  
68 Creates a new SPF record C<redirect> modifier object by parsing the string and
69 any options given.
70  
71 =back
72  
73 =head2 Class methods
74  
75 The following class methods are provided:
76  
77 =over
78  
79 =item B<name>: returns I<string>
80  
81 Returns B<'redirect'>.
82  
83 =item B<name_pattern>: returns I<Regexp>
84  
85 Returns a regular expression that matches a modifier name of B<'redirect'>.
86  
87 =item B<precedence>: returns I<real>
88  
89 Returns a precedence value of B<0.8>. See L<Mail::SPF::Mod/precedence>.
90  
91 =back
92  
93 =head2 Instance methods
94  
95 The following instance methods are provided:
96  
97 =over
98  
99 =cut
100  
101 0 ▶sub parse_params {
Subroutine parse_params: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my ($self) = @_;
103 0 $self->parse_domain_spec(TRUE);
104 0 return;
105 }
106  
107 =item B<params>
108  
109 See L<Mail::SPF::Mod/params>.
110  
111 =cut
112  
113 0 ▶sub params {
Subroutine params: not called CC=1 SCAR=6.9
Pod documented
114 0 my ($self) = @_;
115 0 return $self->{domain_spec};
116 }
117  
118 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
119  
120 Returns the C<domain-spec> parameter of the modifier.
121  
122 =cut
123  
124 # Make read-only accessor:
125 5 __PACKAGE__->make_accessor('domain_spec', TRUE);
126  
127 =item B<process($server, $request, $result)>: throws I<Mail::SPF::Result>
128  
129 If no mechanism matched during the evaluation of the current SPF record,
130 performs a recursive SPF check using the given SPF server and request objects
131 and substituting the modifier's target domain name for the request's authority
132 domain. The result of the recursive SPF check is then thrown as the result of
133 the current record's evaluation. However, if the target domain has no
134 acceptable SPF record, a C<permerror> result is thrown. See RFC 4408, 6.1, for
135 details.
136  
137 =cut
138  
139 0 ▶sub process {
Subroutine process: not called CC=3 SCAR=24.8
Pod documented
140 0 my ($self, $server, $request, $result) = @_;
141  
142 0 $server->count_dns_interactive_term($request);
143  
144 # Only perform redirection if no mechanism matched (RFC 4408, 6.1/1):
145 0 ▶ $result->isa('Mail::SPF::Result::NeutralByDefault')
Branch: 1 branch
BranchTrueFalseTotal
$result->isa("Mail::SPF::Result::NeutralByDefault") or return 0 0 0
146 or return;
147  
148 # Create sub-request with mutated authority domain:
149 0 my $authority_domain = $self->{domain_spec}->new(server => $server, request => $request);
150 0 my $sub_request = $request->new_sub_request(authority_domain => $authority_domain);
151  
152 # Process sub-request:
153 0 $result = $server->process($sub_request);
154  
155 # Translate result of sub-request (RFC 4408, 6.1/4):
156 0 ▶ $server->throw_result('permerror', $request,
Branch: 1 branch
BranchTrueFalseTotal
if $result->isa("Mail::SPF::Result::None") 0 0 0
157 "Redirect domain '$authority_domain' has no applicable sender policy")
158 if $result->isa('Mail::SPF::Result::None');
159  
160 # Propagate any other results as-is:
161 0 $result->throw();
162 }
163  
164 =back
165  
166 See L<Mail::SPF::Mod> for other supported instance methods.
167  
168 =head1 SEE ALSO
169  
170 L<Mail::SPF>, L<Mail::SPF::Mod>, L<Mail::SPF::Term>, L<Mail::SPF::Record>
171  
172 L<http://tools.ietf.org/html/rfc4408>
173  
174 For availability, support, and license information, see the README file
175 included with Mail::SPF.
176  
177 =head1 AUTHORS
178  
179 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
180  
181 =cut
182  
183 5 TRUE;
« SPF/Mech/A.pm ↑ Summary SPF/Result.pm »