SPF/Base.pm

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