SPF/Mech/Include.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran 25.0% 2 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.0% 9 / 10 Podpod 66.6% 2 / 3 totaltotal 72.4% 50 / 69 CC 7 SCAR 16.0
CC
7
Cov
74%
match
9.9
params
6.0
BEGIN
1.0
CRAP 5.0
« SPF/Util.pm ↑ Summary SPF/Term.pm »
1 #
2 # Mail::SPF::Mech::Include
3 # SPF record "include" mechanism class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Include.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mech::Include;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mech::Include - SPF record C<include> mechanism 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 base 'Mail::SPF::Mech';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 5 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 ▶use constant name => 'include';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 5 ▶use constant name_pattern => qr/${\name}/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 =head1 DESCRIPTION
37  
38 An object of class B<Mail::SPF::Mech::Include> represents an SPF record
39 mechanism of type C<include>.
40  
41 =head2 Constructors
42  
43 The following constructors are provided:
44  
45 =over
46  
47 =item B<new(%options)>: returns I<Mail::SPF::Mech::Include>
48  
49 Creates a new SPF record C<include> mechanism object.
50  
51 %options is a list of key/value pairs representing any of the following
52 options:
53  
54 =over
55  
56 =item B<qualifier>
57  
58 =item B<domain_spec>
59  
60 See L<Mail::SPF::Mech/new>.
61  
62 =back
63  
64 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::Include>;
65 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech>
66  
67 Creates a new SPF record C<include> mechanism object by parsing the string and
68 any options given.
69  
70 =back
71  
72 =head2 Class methods
73  
74 The following class methods are provided:
75  
76 =over
77  
78 =item B<default_qualifier>
79  
80 =item B<qualifier_pattern>
81  
82 See L<Mail::SPF::Mech/Class methods>.
83  
84 =item B<name>: returns I<string>
85  
86 Returns B<'include'>.
87  
88 =item B<name_pattern>: returns I<Regexp>
89  
90 Returns a regular expression that matches a mechanism name of B<'include'>.
91  
92 =back
93  
94 =head2 Instance methods
95  
96 The following instance methods are provided:
97  
98 =over
99  
100 =cut
101  
102 6 ▶sub parse_params {
Subroutine parse_params: called CC=1 SCAR=0.0
Pod undocumented
103 6 my ($self) = @_;
104 6 $self->parse_domain_spec(TRUE);
105 6 return;
106 }
107  
108 =item B<text>
109  
110 =item B<qualifier>
111  
112 =item B<params>
113  
114 =cut
115  
116 0 ▶sub params {
Subroutine params: not called CC=2 SCAR=17.9
Pod documented
117 0 my ($self) = @_;
118 0 ▶ return defined($self->{domain_spec}) ? ':' . $self->{domain_spec} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'domain_spec'} ? : 0 0 0
119 }
120  
121 =item B<stringify>
122  
123 See L<Mail::SPF::Mech/Instance methods>.
124  
125 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
126  
127 Returns the C<domain-spec> parameter of the mechanism.
128  
129 =cut
130  
131 # Make read-only accessor:
132 5 __PACKAGE__->make_accessor('domain_spec', TRUE);
133  
134 =item B<match($server, $request)>: returns I<boolean>
135  
136 Performs a recursive SPF check using the given SPF server and request objects
137 and substituting the mechanism's target domain name for the request's authority
138 domain. The result of the recursive SPF check is translated as follows:
139  
140 Recursive result | Effect
141 ------------------+-----------------
142 pass | return true
143 fail | return false
144 softfail | return false
145 neutral | return false
146 none | throw PermError
147 permerror | throw PermError
148 temperror | throw TempError
149  
150 See RFC 4408, 5.2, for the exact algorithm used.
151  
152 =cut
153  
154 6 ▶sub match {
Subroutine match: called CC=6 SCAR=22.9
Pod documented
155 6 my ($self, $server, $request) = @_;
156  
157 6 $server->count_dns_interactive_term($request);
158  
159 # Create sub-request with mutated authority domain:
160 6 my $authority_domain = $self->domain($server, $request);
161 6 my $sub_request = $request->new_sub_request(authority_domain => $authority_domain);
162  
163 # Process sub-request:
164 6 my $result = $server->process($sub_request);
165  
166 # Translate result of sub-request (RFC 4408, 5/9):
167  
168 6 ▶ return TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $result->isa("Mail::SPF::Result::Pass") 0 6 6
169 if $result->isa('Mail::SPF::Result::Pass');
170  
171 6 ▶ return FALSE
Branch: 1 branch
BranchTrueFalseTotal
if $result->isa("Mail::SPF::Result::Fail") or $result->isa("Mail::SPF::Result::SoftFail") or $result->isa("Mail::SPF::Result::Neutral") 6 0 6
Condition33%2/6
$result->isa("Mail::SPF::Result::Fail") or $result->isa("Mail::SPF::Result::SoftFail") or $result->isa("Mail::SPF::Result::Neutral")
l!l&&r!l&&!r
600
$result->isa("Mail::SPF::Result::Fail") or $result->isa("Mail::SPF::Result::SoftFail")
l!l&&r!l&&!r
600
MC/DC0%0/3
$result->isa("Mail::SPF::Result::Fail") or $result->isa("Mail::SPF::Result::SoftFail") or $result->isa("Mail::SPF::Result::Neutral")
$result->isa("Mail::SPF::Result::Fail") $result->isa("Mail::SPF::Result::SoftFail") $result->isa("Mail::SPF::Result::Neutral")
Truth table25%1/4
A or B or C
A= $result->isa("Mail::SPF::Result::Fail")B= $result->isa("Mail::SPF::Result::SoftFail")C= $result->isa("Mail::SPF::Result::Neutral")
ABCresult
1XX1
01X1
0011
0000
172 if $result->isa('Mail::SPF::Result::Fail')
173 or $result->isa('Mail::SPF::Result::SoftFail')
174 or $result->isa('Mail::SPF::Result::Neutral');
175  
176 0 ▶ $server->throw_result('permerror', $request,
Branch: 1 branch
BranchTrueFalseTotal
if $result->isa("Mail::SPF::Result::None") 0 0 0
177 "Included domain '$authority_domain' has no applicable sender policy")
178 if $result->isa('Mail::SPF::Result::None');
179  
180 # Propagate any other results (including {Perm,Temp}Error) as-is:
181 0 $result->throw();
182 }
183  
184 =back
185  
186 =head1 SEE ALSO
187  
188 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>
189  
190 L<http://tools.ietf.org/html/rfc4408>
191  
192 For availability, support, and license information, see the README file
193 included with Mail::SPF.
194  
195 =head1 AUTHORS
196  
197 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
198  
199 =cut
200  
201 5 TRUE;
« SPF/Util.pm ↑ Summary SPF/Term.pm »