SPF/v2/Record.pm

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