SPF/Mech/Exists.pm

filter: Statementstmt 100% 38 / 38 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 66.6% 2 / 3 totaltotal 94.7% 54 / 57 CC 5 SCAR 7.0
CC
5
Cov
95%
match
4.0
params
2.1
BEGIN
1.0
CRAP 2.0
« SPF/Mod/Exp.pm ↑ Summary SPF/Mech/IP6.pm »
1 #
2 # Mail::SPF::Mech::Exists
3 # SPF record "exists" mechanism class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Exists.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mech::Exists;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mech::Exists - SPF record C<exists> 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 => 'exists';
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::Exists> represents an SPF record
39 mechanism of type C<exists>.
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::Exists>
48  
49 Creates a new SPF record C<exists> 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::Exists>;
65 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech>
66  
67 Creates a new SPF record C<exists> 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<'exists'>.
87  
88 =item B<name_pattern>: returns I<Regexp>
89  
90 Returns a regular expression that matches a mechanism name of B<'exists'>.
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 1 ▶sub params {
Subroutine params: called CC=2 SCAR=7.2
Pod documented
117 1 my ($self) = @_;
118 1 ▶ return defined($self->{domain_spec}) ? ':' . $self->{domain_spec} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'domain_spec'} ? : 1 0 1
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 Checks whether a DNS C<A> record exists for the mechanism's target domain name,
137 and returns B<true> if one does, or B<false> otherwise. See RFC 4408, 5.7, for
138 details.
139  
140 =cut
141  
142 6 ▶sub match {
Subroutine match: called CC=4 SCAR=13.9
Pod documented
143 6 my ($self, $server, $request) = @_;
144  
145 6 $server->count_dns_interactive_term($request);
146  
147 6 my $domain = $self->domain($server, $request);
148 6 my $packet = $server->dns_lookup($domain, 'A');
149 6 ▶ my @rrs = $packet->answer
Branch: 1 branch
BranchTrueFalseTotal
my(@rrs) = $packet->answer or $server->count_void_dns_lookup($request) 1 5 6
150 or $server->count_void_dns_lookup($request);
151  
152 6 foreach my $rr (@rrs) {
153 1 ▶ return TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $rr->type eq "A" 1 0 1
154 if $rr->type eq 'A';
155 }
156 5 return FALSE;
157 }
158  
159 =back
160  
161 =head1 SEE ALSO
162  
163 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>
164  
165 L<http://tools.ietf.org/html/rfc4408>
166  
167 For availability, support, and license information, see the README file
168 included with Mail::SPF.
169  
170 =head1 AUTHORS
171  
172 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
173  
174 =cut
175  
176 5 TRUE;
« SPF/Mod/Exp.pm ↑ Summary SPF/Mech/IP6.pm »