SPF/Mech/IP4.pm

filter: Statementstmt 70.5% 24 / 34 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 66.6% 2 / 3 totaltotal 64.7% 33 / 51 CC 3 SCAR 10.1
CC
3
Cov
63%
params
6.0
match
6.0
parse_params
2.0
CRAP 2.8
« SPF/Mech/IP6.pm ↑ Summary SPF/Mech/PTR.pm »
1 #
2 # Mail::SPF::Mech::IP4
3 # SPF record "ip4" mechanism class.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: IP4.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Mech::IP4;
12  
13 =head1 NAME
14  
15 Mail::SPF::Mech::IP4 - SPF record C<ip4> 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 => 'ip4';
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::IP4> represents an SPF record mechanism
37 of type C<ip4>.
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::IP4>
46  
47 Creates a new SPF record C<ip4> 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<ip_network>
57  
58 See L<Mail::SPF::Mech/new>.
59  
60 =back
61  
62 =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mech::IP4>;
63 throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMech>
64  
65 Creates a new SPF record C<ip4> mechanism object by parsing the string and
66 any options given.
67  
68 =back
69  
70 =head2 Class methods
71  
72 The following class methods are provided:
73  
74 =over
75  
76 =item B<default_qualifier>
77  
78 =item B<default_ipv4_prefix_length>
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<'ip4'>.
87  
88 =item B<name_pattern>: returns I<Regexp>
89  
90 Returns a regular expression that matches a mechanism name of B<'ip4'>.
91  
92 =back
93  
94 See L<Mail::SPF::Mech> for other supported class methods.
95  
96 =head2 Instance methods
97  
98 The following instance methods are provided:
99  
100 =over
101  
102 =cut
103  
104 sub parse_params {
105 0 ▶ my ($self) = @_;
Subroutine parse_params: not called CC=1 SCAR=6.9
Pod undocumented
106 0 $self->parse_ipv4_network(TRUE);
107 0 return;
108 }
109  
110 =item B<text>
111  
112 =item B<qualifier>
113  
114 =item B<params>
115  
116 =cut
117  
118 sub params {
119 0 ▶ my ($self) = @_;
Subroutine params: not called CC=2 SCAR=17.9
Pod documented
120 0 my $params = ':' . $self->{ip_network}->addr;
121 $params .= '/' . $self->{ip_network}->masklen
122 0 ▶ if $self->{ip_network}->masklen != $self->default_ipv4_prefix_length;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ip_network"}->masklen != $self->default_ipv4_prefix_length 0 0 0
123 0 return $params;
124 }
125  
126 =item B<stringify>
127  
128 See L<Mail::SPF::Mech/Instance methods>.
129  
130 =item B<ip_network>: returns I<NetAddr::IP>
131  
132 Returns the IP address network parameter of the mechanism.
133  
134 =cut
135  
136 # Make read-only accessors:
137 __PACKAGE__->make_accessor($_, TRUE)
138 1 foreach qw(ip_network ip_address ipv4_prefix_length);
139  
140 =item B<match($server, $request)>: returns I<boolean>
141  
142 Returns B<true> if the mechanism's C<ip_network> equals or contains the given
143 request's IP address, or B<false> otherwise. See RFC 4408, 5.6, for details.
144  
145 =cut
146  
147 sub match {
148 0 ▶ my ($self, $server, $request) = @_;
Subroutine match: not called CC=2 SCAR=17.9
Pod documented
149 0 ▶ my $ip_network_v6 =
Branch: 1 branch
BranchTrueFalseTotal
$self->ip_network->version == 4 ? : 0 0 0
150 $self->ip_network->version == 4 ?
151 Mail::SPF::Util->ipv4_address_to_ipv6($self->ip_network)
152 : $self->ip_network;
153 0 return $ip_network_v6->contains($request->ip_address_v6);
154 }
155  
156 =back
157  
158 =head1 SEE ALSO
159  
160 L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>, L<Mail::SPF::Mech>
161  
162 L<http://tools.ietf.org/html/rfc4408>
163  
164 For availability, support, and license information, see the README file
165 included with Mail::SPF.
166  
167 =head1 AUTHORS
168  
169 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
170  
171 =cut
172  
173 1 TRUE;
« SPF/Mech/IP6.pm ↑ Summary SPF/Mech/PTR.pm »