SPF/Mech/A.pm

filter: Statementstmt 64.8% 24 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 70.0% 7 / 10 Podpod 66.6% 2 / 3 totaltotal 50.0% 33 / 66 CC 6 SCAR 28.6
CC
6
Cov
49%
params
42.0
parse_params
2.0
match
2.0
CRAP 17.5
« SPF/Request.pm ↑ Summary SPF/Mech/Include.pm »
1 #
2 # Mail::SPF::Mech::A
3 # SPF record "a" mechanism class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: A.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mech::A;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mech::A - SPF record C<a> 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::SenderIPAddrMech';
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 => 'a';
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::A> represents an SPF record mechanism of
37 type C<a>.
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::A>
46  
47 Creates a new SPF record C<a> 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 =item B<ipv4_prefix_length>
59  
60 =item B<ipv6_prefix_length>
61  
62 See L<Mail::SPF::Mech/new>.
63  
64 =back
65  
66 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::A>;
67 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech>
68  
69 Creates a new SPF record C<a> mechanism object by parsing the string and
70 any options given.
71  
72 =back
73  
74 =head2 Class methods
75  
76 The following class methods are provided:
77  
78 =over
79  
80 =item B<default_qualifier>
81  
82 =item B<default_ipv4_prefix_length>
83  
84 =item B<default_ipv6_prefix_length>
85  
86 =item B<qualifier_pattern>
87  
88 See L<Mail::SPF::Mech/Class methods>.
89  
90 =item B<name>: returns I<string>
91  
92 Returns B<'a'>.
93  
94 =item B<name_pattern>: returns I<Regexp>
95  
96 Returns a regular expression that matches a mechanism name of B<'a'>.
97  
98 =back
99  
100 =head2 Instance methods
101  
102 The following instance methods are provided:
103  
104 =over
105  
106 =cut
107  
108 sub parse_params {
109 0 ▶ my ($self) = @_;
Subroutine parse_params: not called CC=1 SCAR=6.9
Pod undocumented
110 0 $self->parse_domain_spec();
111 0 $self->parse_ipv4_ipv6_prefix_lengths();
112 0 return;
113 }
114  
115 =item B<text>
116  
117 =item B<qualifier>
118  
119 =item B<params>
120  
121 =cut
122  
123 sub params {
124 0 ▶ my ($self) = @_;
Subroutine params: not called CC=6 SCAR=37.4
Pod documented
125 0 my $params;
126 $params .= ':' . $self->{domain_spec}
127 0 ▶ if defined($self->{domain_spec});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"domain_spec"} 0 0 0
128 $params .= '/' . $self->{ipv4_prefix_length}
129 if defined($self->{ipv4_prefix_length})
130 0 ▶ and $self->{ipv4_prefix_length} != $self->default_ipv4_prefix_length;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length 0 0 0
Condition0%0/3
defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
defined $self->{"ipv4_prefix_length"} $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
Truth table0%0/3
A and B
A= defined $self->{"ipv4_prefix_length"}B= $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
ABresult
0X0
100
111
131 $params .= '//' . $self->{ipv6_prefix_length}
132 if defined($self->{ipv6_prefix_length})
133 0 ▶ and $self->{ipv6_prefix_length} != $self->default_ipv6_prefix_length;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length 0 0 0
Condition0%0/3
defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
defined $self->{"ipv6_prefix_length"} $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
Truth table0%0/3
A and B
A= defined $self->{"ipv6_prefix_length"}B= $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
ABresult
0X0
100
111
134 0 return $params;
135 }
136  
137 =item B<stringify>
138  
139 =item B<domain>
140  
141 =item B<match_in_domain>
142  
143 See L<Mail::SPF::Mech/Instance methods>.
144  
145 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
146  
147 Returns the C<domain-spec> parameter of the mechanism.
148  
149 =item B<ipv4_prefix_length>: returns I<integer>
150  
151 Returns the IPv4 network prefix length of the mechanism.
152  
153 =item B<ipv6_prefix_length>: returns I<integer>
154  
155 Returns the IPv6 network prefix length of the mechanism.
156  
157 =cut
158  
159 # Make read-only accessors:
160 __PACKAGE__->make_accessor($_, TRUE)
161 1 foreach qw(domain_spec ipv4_prefix_length ipv6_prefix_length);
162  
163 =item B<match($server, $request)>: returns I<boolean>
164  
165 Checks whether the mechanism's target domain name (that is, any of its DNS C<A>
166 or C<AAAA> host addresses) matches the given request's IP address (see
167 L<Mail::SPF::Request/ip_address>), and returns B<true> if it does, or B<false>
168 otherwise. The mechanism's IP network prefix lengths are respected when
169 matching address records against the request's IP address. See RFC 4408, 5,
170 for the exact algorithm used.
171  
172 =cut
173  
174 sub match {
175 0 ▶ my ($self, $server, $request) = @_;
Subroutine match: not called CC=1 SCAR=6.9
Pod documented
176 0 $server->count_dns_interactive_term($request);
177 0 return $self->match_in_domain($server, $request);
178 }
179  
180 =back
181  
182 =head1 SEE ALSO
183  
184 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>
185  
186 L<http://tools.ietf.org/html/rfc4408>
187  
188 For availability, support, and license information, see the README file
189 included with Mail::SPF.
190  
191 =head1 AUTHORS
192  
193 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
194  
195 =cut
196  
197 1 TRUE;
« SPF/Request.pm ↑ Summary SPF/Mech/Include.pm »