SPF/Mech/A.pm

filter: Statementstmt 100% 38 / 38 Branchbran 50.0% 3 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 82.0% 55 / 67 CC 6 SCAR 13.5
CC
6
Cov
86%
params
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« SPF/Exception.pm ↑ Summary SPF/Mod/Redirect.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.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::SenderIPAddrMech';
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 => 'a';
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::A> represents an SPF record mechanism of
39 type C<a>.
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::A>
48  
49 Creates a new SPF record C<a> 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 =item B<ipv4_prefix_length>
61  
62 =item B<ipv6_prefix_length>
63  
64 See L<Mail::SPF::Mech/new>.
65  
66 =back
67  
68 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::A>;
69 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech>
70  
71 Creates a new SPF record C<a> mechanism object by parsing the string and
72 any options given.
73  
74 =back
75  
76 =head2 Class methods
77  
78 The following class methods are provided:
79  
80 =over
81  
82 =item B<default_qualifier>
83  
84 =item B<default_ipv4_prefix_length>
85  
86 =item B<default_ipv6_prefix_length>
87  
88 =item B<qualifier_pattern>
89  
90 See L<Mail::SPF::Mech/Class methods>.
91  
92 =item B<name>: returns I<string>
93  
94 Returns B<'a'>.
95  
96 =item B<name_pattern>: returns I<Regexp>
97  
98 Returns a regular expression that matches a mechanism name of B<'a'>.
99  
100 =back
101  
102 =head2 Instance methods
103  
104 The following instance methods are provided:
105  
106 =over
107  
108 =cut
109  
110 6 ▶sub parse_params {
Subroutine parse_params: called CC=1 SCAR=0.0
Pod undocumented
111 6 my ($self) = @_;
112 6 $self->parse_domain_spec();
113 6 $self->parse_ipv4_ipv6_prefix_lengths();
114 6 return;
115 }
116  
117 =item B<text>
118  
119 =item B<qualifier>
120  
121 =item B<params>
122  
123 =cut
124  
125 2 ▶sub params {
Subroutine params: called CC=6 SCAR=20.9
Pod documented
126 2 my ($self) = @_;
127 2 my $params;
128 $params .= ':' . $self->{domain_spec}
129 2 ▶ if defined($self->{domain_spec});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"domain_spec"} 0 2 2
130 $params .= '/' . $self->{ipv4_prefix_length}
131 if defined($self->{ipv4_prefix_length})
132 2 ▶ 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 2 2
Condition33%1/3
defined $self->{"ipv4_prefix_length"} and $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
!ll&&!rl&&r
020
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 table33%1/3
A and B
A= defined $self->{"ipv4_prefix_length"}B= $self->{"ipv4_prefix_length"} != $self->default_ipv4_prefix_length
ABresult
0X0
100
111
133 $params .= '//' . $self->{ipv6_prefix_length}
134 if defined($self->{ipv6_prefix_length})
135 2 ▶ 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 2 2
Condition33%1/3
defined $self->{"ipv6_prefix_length"} and $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
!ll&&!rl&&r
200
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 table33%1/3
A and B
A= defined $self->{"ipv6_prefix_length"}B= $self->{"ipv6_prefix_length"} != $self->default_ipv6_prefix_length
ABresult
0X0
100
111
136 2 return $params;
137 }
138  
139 =item B<stringify>
140  
141 =item B<domain>
142  
143 =item B<match_in_domain>
144  
145 See L<Mail::SPF::Mech/Instance methods>.
146  
147 =item B<domain_spec>: returns I<Mail::SPF::MacroString>
148  
149 Returns the C<domain-spec> parameter of the mechanism.
150  
151 =item B<ipv4_prefix_length>: returns I<integer>
152  
153 Returns the IPv4 network prefix length of the mechanism.
154  
155 =item B<ipv6_prefix_length>: returns I<integer>
156  
157 Returns the IPv6 network prefix length of the mechanism.
158  
159 =cut
160  
161 # Make read-only accessors:
162 __PACKAGE__->make_accessor($_, TRUE)
163 5 foreach qw(domain_spec ipv4_prefix_length ipv6_prefix_length);
164  
165 =item B<match($server, $request)>: returns I<boolean>
166  
167 Checks whether the mechanism's target domain name (that is, any of its DNS C<A>
168 or C<AAAA> host addresses) matches the given request's IP address (see
169 L<Mail::SPF::Request/ip_address>), and returns B<true> if it does, or B<false>
170 otherwise. The mechanism's IP network prefix lengths are respected when
171 matching address records against the request's IP address. See RFC 4408, 5,
172 for the exact algorithm used.
173  
174 =cut
175  
176 6 ▶sub match {
Subroutine match: called CC=1 SCAR=0.0
Pod documented
177 6 my ($self, $server, $request) = @_;
178 6 $server->count_dns_interactive_term($request);
179 6 return $self->match_in_domain($server, $request);
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 5 TRUE;
« SPF/Exception.pm ↑ Summary SPF/Mod/Redirect.pm »