SPF/Mod/Exp.pm

filter: Statementstmt 69.2% 36 / 52 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.7% 11 / 17 Podpod 66.6% 2 / 3 totaltotal 62.8% 49 / 78 CC 4 SCAR 16.1
CC
4
Cov
62%
__ANON__
20.0
parse_params
2.0
params
2.0
CRAP 5.0
« SPF/Mech/Exists.pm ↑ Summary SPF/Exception.pm »
1 #
2 # Mail::SPF::Mod::Exp
3 # SPF record "exp" modifier class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Exp.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mod::Exp;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mod::Exp - SPF record C<exp> modifier 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 Mail::SPF::Mod;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use base 'Mail::SPF::GlobalMod';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use Error ':try';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 ▶use Mail::SPF::MacroString;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use constant name => 'exp';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use constant name_pattern => qr/${\name}/i;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 1 ▶use constant precedence => 0.2;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 =head1 DESCRIPTION
42  
43 An object of class B<Mail::SPF::Mod::Exp> represents an SPF record modifier of
44 type C<exp>.
45  
46 =head2 Constructors
47  
48 The following constructors are provided:
49  
50 =over
51  
52 =item B<new(%options)>: returns I<Mail::SPF::Mod::Exp>
53  
54 Creates a new SPF record C<exp> modifier object.
55  
56 %options is a list of key/value pairs representing any of the following
57 options:
58  
59 =over
60  
61 =item B<domain_spec>
62  
63 See L<Mail::SPF::Mod/new>.
64  
65 =back
66  
67 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mod::Exp>;
68 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMod>
69  
70 Creates a new SPF record C<exp> modifier object by parsing the string and
71 any options given.
72  
73 =back
74  
75 =head2 Class methods
76  
77 The following class methods are provided:
78  
79 =over
80  
81 =item B<name>: returns I<string>
82  
83 Returns B<'exp'>.
84  
85 =item B<name_pattern>: returns I<Regexp>
86  
87 Returns a regular expression that matches a modifier name of B<'exp'>.
88  
89 =item B<precedence>: returns I<real>
90  
91 Returns a precedence value of B<0.2>. See L<Mail::SPF::Mod/precedence>.
92  
93 =back
94  
95 =head2 Instance methods
96  
97 The following instance methods are provided:
98  
99 =over
100  
101 =cut
102  
103 sub parse_params {
104 0 ▶ my ($self) = @_;
Subroutine parse_params: not called CC=1 SCAR=6.9
Pod undocumented
105 0 $self->parse_domain_spec(TRUE);
106 0 return;
107 }
108  
109 =item B<params>
110  
111 See L<Mail::SPF::Mod/params>.
112  
113 =cut
114  
115 sub params {
116 0 ▶ my ($self) = @_;
Subroutine params: not called CC=1 SCAR=6.9
Pod documented
117 0 return $self->{domain_spec};
118 }
119  
120 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
121  
122 Returns the C<domain-spec> parameter of the modifier.
123  
124 =cut
125  
126 # Make read-only accessor:
127 1 __PACKAGE__->make_accessor('domain_spec', TRUE);
128  
129 =item B<process($server, $request, $result)>
130  
131 If the given SPF result is a C<fail> result, retrieves the authority domain's
132 explanation string from the modifier's target domain and attaches it to the SPF
133 result. If an error occurs during the retrieval of the explanation string,
134 does nothing, as if the modifier was not present. See RFC 4408, 6.2, for
135 details.
136  
137 =cut
138  
139 sub process {
140 0 ▶ my ($self, $server, $request, $result) = @_;
Subroutine process: not called CC=1 SCAR=6.9
Pod documented
141  
142 try {
143 0 ▶ my $exp_domain = $self->{domain_spec}->new(server => $server, request => $request);
Subroutine __ANON__: not called CC=4 SCAR=30.0
144 0 my $txt_packet = $server->dns_lookup($exp_domain, 'TXT');
145 0 my @txt_rrs = grep($_->type eq 'TXT', $txt_packet->answer);
146 0 ▶ @txt_rrs > 0
Branch: 1 branch
BranchTrueFalseTotal
@txt_rrs > 0 or $server->throw_result("permerror", $request, "No authority explanation string available at domain '${exp_domain}'") 0 0 0
147 or $server->throw_result('permerror', $request,
148 "No authority explanation string available at domain '$exp_domain'"); # RFC 4408, 6.2/4
149 0 ▶ @txt_rrs == 1
Branch: 1 branch
BranchTrueFalseTotal
@txt_rrs == 1 or $server->throw_result("permerror", $request, "Redundant authority explanation strings found at domain '${exp_domain}'") 0 0 0
150 or $server->throw_result('permerror', $request,
151 "Redundant authority explanation strings found at domain '$exp_domain'"); # RFC 4408, 6.2/4
152  
153 # char_str_list method is 'historical', use as a fallback for Net::DNS prior to 0.69
154 # where txtdata is not available.
155 # join with no intervening spaces, RFC 6376
156 # must call txtdata() in a list context
157 0 ▶ my $text = $txt_rrs[0]->can('txtdata')
Branch: 1 branch
BranchTrueFalseTotal
$txt_rrs[0]->can('txtdata') ? : 0 0 0
158 ? join('', $txt_rrs[0]->txtdata)
159 : join('', $txt_rrs[0]->char_str_list);
160 0 my $explanation = Mail::SPF::MacroString->new(
161 text => $text,
162 server => $server,
163 request => $request,
164 is_explanation => TRUE
165 );
166  
167 0 $request->state('authority_explanation', $explanation);
168 }
169 # Ignore DNS and other errors:
170 ▶ catch Mail::SPF::EDNSError with {}
Subroutine __ANON__: not called CC=1 SCAR=0.0
171 0 ▶ catch Mail::SPF::Result::Error with {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
172  
173 0 return;
174 }
175  
176 =back
177  
178 See L<Mail::SPF::Mod> for other supported instance methods.
179  
180 =head1 SEE ALSO
181  
182 L<Mail::SPF>, L<Mail::SPF::Mod>, L<Mail::SPF::Term>, L<Mail::SPF::Record>
183  
184 L<http://tools.ietf.org/html/rfc4408>
185  
186 For availability, support, and license information, see the README file
187 included with Mail::SPF.
188  
189 =head1 AUTHORS
190  
191 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
192  
193 =cut
194  
195 1 TRUE;
« SPF/Mech/Exists.pm ↑ Summary SPF/Exception.pm »