SPF/Mech/Include.pm

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