SPF/Base.pm

filter: Statementstmt 89.5% 43 / 48 Branchbran 50.0% 7 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 91.6% 11 / 12 Podpod 66.6% 2 / 3 totaltotal 79.2% 65 / 82 CC 9 SCAR 12.6
CC
9
Cov
80%
__ANON__
12.0
make_accessor
3.3
__ANON__
3.1
CRAP 3.5
« SPF/Exception.pm ↑ Summary SPF/Mod/Redirect.pm »
1 #
2 # Mail::SPF::Base
3 # Base class for Mail::SPF classes.
4 #
5 # (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
6 # 2005 Shevek <cpan@anarres.org>
7 # $Id: Base.pm 57 2012-01-30 08:15:31Z julian $
8 #
9 ##############################################################################
10  
11 package Mail::SPF::Base;
12  
13 =head1 NAME
14  
15 Mail::SPF::Base - Base class for Mail::SPF classes
16  
17 =head1 VERSION
18  
19 version 3.20250505
20  
21 =cut
22  
23 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 7 ▶use Error ':try';
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 7 ▶use Mail::SPF::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 7 ▶use constant TRUE => (0 == 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 7 ▶use constant FALSE => not TRUE;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 =head1 SYNOPSIS
34  
35 use base 'Mail::SPF::Base';
36  
37 sub new {
38 my ($class, @options) = @_;
39 my $self = $class->SUPER::new(@options);
40 ...
41 return $self;
42 }
43  
44 =head1 DESCRIPTION
45  
46 B<Mail::SPF::Base> is a common base class for all B<Mail::SPF> classes.
47  
48 =head2 Constructor
49  
50 The following constructor is provided:
51  
52 =over
53  
54 =item B<new(%options)>: returns I<Mail::SPF::Base>
55  
56 Creates a new object of the class on which the constructor was invoked. The
57 provided options are stored as key/value pairs in the new object.
58  
59 The C<new> constructor may also be called on an object, in which case the
60 object is cloned. Any options provided override those from the old object.
61  
62 There are no common options defined in B<Mail::SPF::Base>.
63  
64 =cut
65  
66 sub new {
67 27 ▶ my ($self, %options) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
68 27 ▶ my $new =
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 2 25 27
69 ref($self) ? # Was new() invoked on a class or an object?
70 { %$self, %options } # Object: clone source object, override fields.
71 : \%options; # Class: create new object.
72 27 return bless($new, $self->class);
73 }
74  
75 =back
76  
77 =head2 Class methods
78  
79 The following class methods are provided:
80  
81 =over
82  
83 =item B<class>: returns I<string>
84  
85 Returns the class name of the class or object on which it is invoked.
86  
87 =cut
88  
89 sub class {
90 27 ▶ my ($self) = @_;
Subroutine class: called CC=2 SCAR=7.1
Pod undocumented
91 27 ▶ return ref($self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
2250
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
92 }
93  
94 =back
95  
96 =head2 Class methods
97  
98 The following class methods are provided:
99  
100 =over
101  
102 =item B<make_accessor($name, $readonly)>: returns I<code-ref>
103  
104 Creates an accessor method in the class on which it is invoked. The accessor
105 has the given name and accesses the object field of the same name. If
106 $readonly is B<true>, the accessor is made read-only.
107  
108 =cut
109  
110 sub make_accessor {
111 92 ▶ my ($class, $name, $readonly) = @_;
Subroutine make_accessor: called CC=3 SCAR=12.0
Pod documented
112 92 ▶ throw Mail::SPF::EClassMethod if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 92 92
113 92 my $accessor_name = "${class}::${name}";
114 92 my $accessor;
115 92 ▶ if ($readonly) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readonly) { } 88 4 92
116 $accessor = sub {
117 65 ▶ local *__ANON__ = $accessor_name;
Subroutine __ANON__: called CC=3 SCAR=11.3
118 65 my ($self, @value) = @_;
119 65 ▶ throw Mail::SPF::EInstanceMethod if not ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 65 65
120 65 ▶ throw Mail::SPF::EReadOnlyValue("$accessor_name is read-only") if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 0 65 65
121 65 return $self->{$name};
122 88 };
123 }
124 else {
125 $accessor = sub {
126 0 ▶ local *__ANON__ = $accessor_name;
Subroutine __ANON__: not called CC=3 SCAR=24.8
127 0 my ($self, @value) = @_;
128 0 ▶ throw Mail::SPF::EInstanceMethod if not ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 0 0
129 0 ▶ $self->{$name} = $value[0] if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 0 0 0
130 0 return $self->{$name};
131 4 };
132 }
133 {
134 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 92 *{$accessor_name} = $accessor;
136 }
137 92 return $accessor;
138 }
139  
140 =back
141  
142 =head2 Instance methods
143  
144 There are no common instance methods defined in B<Mail::SPF::Base>.
145  
146 =head1 SEE ALSO
147  
148 L<Mail::SPF>
149  
150 For availability, support, and license information, see the README file
151 included with Mail::SPF.
152  
153 =head1 AUTHORS
154  
155 Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
156  
157 =cut
158  
159 7 TRUE;
« SPF/Exception.pm ↑ Summary SPF/Mod/Redirect.pm »