SPF/v2/Record.pm

filter: Statementstmt 58.4% 31 / 53 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 33.3% 1 / 3 totaltotal 43.6% 41 / 94 CC 13 SCAR 30.2
CC
13
Cov
41%
new
42.0
parse_version_tag
30.0
version_tag
20.0
CRAP 20.5
« SPF/Server.pm ↑ Summary SPF/Request.pm »
1 #
2 # Mail::SPF::v2::Record
3 # Sender ID ("spf2.0") record class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Record.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::v2::Record;
12  
13 =head1 NAME
14  
15 Mail::SPF::v2::Record - Sender ID ("spf2.0") record 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::Record';
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 mech_classes => {
32 all => 'Mail::SPF::Mech::All',
33 ip4 => 'Mail::SPF::Mech::IP4',
34 ip6 => 'Mail::SPF::Mech::IP6',
35 a => 'Mail::SPF::Mech::A',
36 mx => 'Mail::SPF::Mech::MX',
37 ptr => 'Mail::SPF::Mech::PTR',
38 'exists' => 'Mail::SPF::Mech::Exists',
39 include => 'Mail::SPF::Mech::Include'
40 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 use constant mod_classes => {
43 redirect => 'Mail::SPF::Mod::Redirect',
44 'exp' => 'Mail::SPF::Mod::Exp'
45 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 eval("require $_")
48 1 foreach values(%{mech_classes()}), values(%{mod_classes()});
49  
50 1 ▶use constant valid_scope => qr/^(?: mfrom | pra )$/x;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 1 use constant version_tag_pattern => qr{
52 spf(2\.0)
53 /
54 ( (?: mfrom | pra ) (?: , (?: mfrom | pra ) )* )
55 (?= \x20 | $ )
56 1 ▶}ix;
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 =head1 SYNOPSIS
59  
60 See L<Mail::SPF::Record>.
61  
62 =head1 DESCRIPTION
63  
64 An object of class B<Mail::SPF::v2::Record> represents a B<Sender ID>
65 (C<spf2.0>) record.
66  
67 =head2 Constructors
68  
69 The following constructors are provided:
70  
71 =over
72  
73 =item B<new(%options)>: returns I<Mail::SPF::v2::Record>
74  
75 Creates a new Sender ID ("spf2.0") record object.
76  
77 %options is a list of key/value pairs representing any of the following
78 options:
79  
80 =over
81  
82 =item B<text>
83  
84 =item B<terms>
85  
86 =item B<global_mods>
87  
88 See L<Mail::SPF::Record/new>.
89  
90 =item B<scopes>
91  
92 I<Required>. See L<Mail::SPF::Record/new>. The B<'mfrom'> and B<'pra'> scopes
93 are supported. There is no default.
94  
95 =back
96  
97 =cut
98  
99 sub new {
100 0 ▶ my ($self, %options) = @_;
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
101 0 $self = $self->SUPER::new(%options);
102  
103 0 ▶ if (not defined($self->{parse_text})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"parse_text"}) 0 0 0
104 # No parsing is intended, so scopes should have been specified:
105 0 ▶ my $scopes = $self->{scopes} || [];
Condition0%0/2
$self->{'scopes'} || []
l!l
00
MC/DC0%0/1
$self->{'scopes'} || []
$self->{'scopes'}
Truth table0%0/2
A
A= $self->{'scopes'}
Aresult
11
00
106 0 ▶ @$scopes > 0
Branch: 1 branch
BranchTrueFalseTotal
@$scopes > 0 or "Mail::SPF::EInvalidScope"->throw("No scopes for spf2.0 record") 0 0 0
107 or throw Mail::SPF::EInvalidScope('No scopes for spf2.0 record');
108 0 foreach my $scope (@$scopes) {
109 0 ▶ $scope =~ $self->valid_scope
Branch: 1 branch
BranchTrueFalseTotal
$scope =~ $self->valid_scope or "Mail::SPF::EInvalidScope"->throw("Invalid scope '${scope}' for spf2.0 record") 0 0 0
110 or throw Mail::SPF::EInvalidScope("Invalid scope '$scope' for spf2.0 record");
111 }
112 }
113  
114 0 return $self;
115 }
116  
117 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::v2::Record>;
118 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidRecordVersion>,
119 I<Mail::SPF::ESyntaxError>
120  
121 Creates a new Sender ID ("spf2.0") record object by parsing the string and
122 any options given.
123  
124 =back
125  
126 =head2 Class methods
127  
128 The following class methods are provided:
129  
130 =over
131  
132 =item B<version_tag_pattern>: returns I<Regexp>
133  
134 Returns a regular expression that matches a version tag of B<'spf2.0/'> plus a
135 comma-separated list of any of the B<'mfrom'> and B<'pra'> scopes. The
136 following are valid version tags:
137  
138 spf2.0/mfrom
139 spf2.0/pra
140 spf2.0/mfrom,pra
141 spf2.0/pra,mfrom
142  
143 =item B<default_qualifier>
144  
145 =item B<results_by_qualifier>
146  
147 See L<Mail::SPF::Record/Class methods>.
148  
149 =back
150  
151 =head2 Instance methods
152  
153 The following instance methods are provided:
154  
155 =over
156  
157 =cut
158  
159 sub parse_version_tag {
160 0 ▶ my ($self) = @_;
Subroutine parse_version_tag: not called CC=5 SCAR=34.0
Pod undocumented
161 0 ▶ if ($self->{parse_text} =~ s/^${\$self->version_tag_pattern}(?:\x20+|$)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'parse_text'} =~ s/^${\$self->version_tag_pattern;}(?:\x20+|$)//) { } 0 0 0
162 0 my $scopes = $self->{scopes} = [ split(/,/, $2) ];
163 0 ▶ @$scopes > 0
Branch: 1 branch
BranchTrueFalseTotal
@$scopes > 0 or "Mail::SPF::EInvalidScope"->throw("No scopes for spf2.0 record") 0 0 0
164 or throw Mail::SPF::EInvalidScope('No scopes for spf2.0 record');
165 0 foreach my $scope (@$scopes) {
166 0 ▶ $scope =~ $self->valid_scope
Branch: 1 branch
BranchTrueFalseTotal
$scope =~ $self->valid_scope or "Mail::SPF::EInvalidScope"->throw("Invalid scope '${scope}' for spf2.0 record") 0 0 0
167 or throw Mail::SPF::EInvalidScope("Invalid scope '$scope' for spf2.0 record");
168 }
169 }
170 else {
171 0 throw Mail::SPF::EInvalidRecordVersion(
172 "Not a 'spf2.0' record: '" . $self->text . "'");
173 }
174 0 return;
175 }
176  
177 =item B<text>
178  
179 =item B<scopes>
180  
181 =item B<terms>
182  
183 =item B<global_mods>
184  
185 =item B<global_mod>
186  
187 =item B<stringify>
188  
189 =item B<eval>
190  
191 See L<Mail::SPF::Record/Instance methods>.
192  
193 =item B<version_tag>: returns I<string>
194  
195 Returns B<'spf2.0/'> plus a comma-separated list of the scopes of the record.
196 See L</version_tag_pattern> for a list of possible return values.
197  
198 =cut
199  
200 sub version_tag {
201 0 ▶ my ($self) = @_;
Subroutine version_tag: not called CC=4 SCAR=30.0
Pod undocumented
202 return 'spf2.0'
203 if not ref($self) # called as class method
204 or not defined($self->{scopes}) # no scopes parsed
205 0 ▶ or not @{$self->{scopes}}; # no scopes specified in record
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and defined $self->{"scopes"} and @{$self->{"scopes"};} 0 0 0
Condition0%0/6
ref $self and defined $self->{"scopes"} and @{$self->{"scopes"};}
!ll&&!rl&&r
000
ref $self and defined $self->{"scopes"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $self and defined $self->{"scopes"} and @{$self->{"scopes"};}
ref $self defined $self->{"scopes"} @{$self->{"scopes"};}
Truth table0%0/4
A and B and C
A= ref $selfB= defined $self->{"scopes"}C= @{$self->{"scopes"};}
ABCresult
0XX0
10X0
1100
1111
206 0 return 'spf2.0/' . join(',', @{$self->{scopes}});
207 }
208  
209 =back
210  
211 =head1 SEE ALSO
212  
213 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>,
214 L<Mail::SPF::Mod>
215  
216 L<http://tools.ietf.org/html/rfc4408>
217  
218 For availability, support, and license information, see the README file
219 included with Mail::SPF.
220  
221 =head1 AUTHORS
222  
223 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
224  
225 =cut
226  
227 1 TRUE;
« SPF/Server.pm ↑ Summary SPF/Request.pm »