Sub/Accessor/Small.pm

filter: Statementstmt 66.9% 194 / 290 Branchbran 42.7% 71 / 166 Conditioncond 22.5% 23 / 102 MC/DCmcdc 3.2% 2 / 61 Subroutinesub 84.9% 45 / 53 Podpod 0.0% 0 / 35 totaltotal 47.3% 335 / 707 CC 120 SCAR 38.5
CC
120
Cov
52%
canonicalize_is
224.1
inline_type_assertion
91.7
install_accessors
67.2
CRAP 46.9
↑ Summary Lexical/Accessor.pm »
1 8 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶no warnings qw( void once uninitialized );
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Sub::Accessor::Small;
7  
8 8 ▶use Carp qw( carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Eval::TypeTiny qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Exporter::Tiny qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Scalar::Util qw( blessed reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 BEGIN {
14 8 *HAS_SUB_UTIL = eval { require Sub::Util }
15 ? sub(){1}
16 8 ▶ : sub(){0};
Subroutine BEGIN: called CC=4 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Sub::Util } } ? : 8 0 8
17 0 *HAS_SUB_NAME = !HAS_SUB_UTIL() && eval { require Sub::Name }
18 ? sub(){1}
19 8 ▶ : sub(){0};
Branch: 1 branch
BranchTrueFalseTotal
!&HAS_SUB_UTIL() && eval { do { require Sub::Name } } ? : 0 8 8
Condition33%1/3
not &HAS_SUB_UTIL() and eval {
!ll&&!rl&&r
800
MC/DC0%0/2
not &HAS_SUB_UTIL() and eval { do { require Sub::Name } }
not &HAS_SUB_UTIL() eval { do { require Sub::Name } }
Truth table33%1/3
not(A) and B
A= not &HAS_SUB_UTIL()B= eval { do { require Sub::Name } }
ABresult
0X0
100
111
20 };
21  
22 BEGIN {
23 *fieldhash =
24 8 eval { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } ||
25 0 eval { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } ||
26 8 ▶ do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash } ;;
Subroutine BEGIN: called CC=3 SCAR=17.3
Condition33%2/6
eval { || do {
l!l&&r!l&&!r
800
eval { or eval {
l!l&&r!l&&!r
800
MC/DC0%0/3
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } || eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } } || do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } } eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } } do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
Truth table25%1/4
A or B || C
A= eval { do { require Hash::FieldHash; \&Hash::FieldHash::fieldhash } }B= eval { do { require Hash::Util::FieldHash; \&Hash::Util::FieldHash::fieldhash } }C= do { require Hash::Util::FieldHash::Compat; \&Hash::Util::FieldHash::Compat::fieldhash }
ABCresult
1XX1
01X1
0011
0000
27 };
28  
29 8 our $AUTHORITY = 'cpan:TOBYINK';
30 8 our $VERSION = '0.013';
31 8 our @ISA = qw/ Exporter::Tiny /;
32  
33 8 fieldhash( our %FIELDS );
34  
35 sub _generate_has : method
36 {
37 8 ▶ my $me = shift;
Subroutine _generate_has: called CC=1 SCAR=0.0
38 8 my (undef, undef, $export_opts) = @_;
39
40 my $code = sub
41 {
42 7 ▶ my $attr = $me->new_from_has($export_opts, @_);
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine has: called CC=1 SCAR=0.0
43 7 $attr->install_accessors;
44 8 };
45
46 8 HAS_SUB_UTIL ? ($code = Sub::Util::set_subname("$me\::has", $code)) :
47 HAS_SUB_NAME ? ($code = Sub::Name::subname("$me\::has", $code)) :
48 ();
49 8 return $code;
50 }
51  
52 {
53 8 my $uniq = 0;
54 sub new_from_has : method
55 {
56 24 ▶ my $me = shift;
Subroutine new_from_has: called CC=6 SCAR=20.3
Pod undocumented
57 24 ▶ my $export_opts = ref($_[0]) eq 'HASH' ? shift(@_) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 24 0 24
58 24 ▶ my ($name, %opts) = (@_%2) ? @_ : (undef, @_);
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 24 0 24
59
60 24 my $package;
61 $package = $export_opts->{into}
62 24 ▶ if defined($export_opts->{into}) && !ref($export_opts->{into});
Branch: 1 branch
BranchTrueFalseTotal
if defined $export_opts->{"into"} and not ref $export_opts->{"into"} 24 0 24
Condition33%1/3
defined $export_opts->{"into"} and not ref $export_opts->{"into"}
!ll&&!rl&&r
0024
MC/DC0%0/2
defined $export_opts->{"into"} and not ref $export_opts->{"into"}
defined $export_opts->{"into"} not ref $export_opts->{"into"}
Truth table33%1/3
A and not(B)
A= defined $export_opts->{"into"}B= not ref $export_opts->{"into"}
ABresult
0X0
100
111
63
64 24 ▶ $me->new(
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 24 0 24
65 slot => $name,
66 id => $uniq++,
67 _export => $export_opts,
68 ($package ? (package => $package) : ()),
69 %opts,
70 );
71 }
72 }
73  
74 8 sub has : method
75 {
76 0 ▶ my $me = shift;
Subroutine has: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my $attr = $me->new_from_has(@_);
78 0 $attr->install_accessors;
79 }
80  
81 sub new : method
82 {
83 24 ▶ my $me = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
84 24 my (%opts) = @_;
85 24 my $self = bless(\%opts, $me);
86 24 $self->canonicalize_opts;
87 24 return $self;
88 }
89  
90 sub install_accessors : method
91 {
92 24 ▶ my $me = shift;
Subroutine install_accessors: called CC=18 SCAR=42.1
Pod undocumented
93
94 24 for my $type (qw( accessor reader writer predicate clearer ))
95 {
96 120 ▶ next unless defined $me->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{$type} 76 44 120
97 44 $me->install_coderef($me->{$type}, $me->$type);
98 }
99
100 24 ▶ if (defined $me->{handles}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"handles"}) 1 23 24
101 1 my $shv_data;
102 1 ▶ if ($me->{traits} or $me->{handles_via}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"traits"} or $me->{"handles_via"}) 1 0 1
Condition33%1/3
$me->{"traits"} or $me->{"handles_via"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$me->{"traits"} or $me->{"handles_via"}
$me->{"traits"} $me->{"handles_via"}
Truth table33%1/3
A or B
A= $me->{"traits"}B= $me->{"handles_via"}
ABresult
1X1
011
000
103 1 my $orig_handles = $me->{handles};
104 1 require Sub::HandlesVia::Toolkit::Plain;
105 $shv_data = 'Sub::HandlesVia::Toolkit::Plain'->clean_spec(
106 $me->{package},
107 $me->{slot},
108 1 +{%$me},
109 );
110 0 ▶ if ($shv_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shv_data) 0 0 0
111 my @default =
112 ref($me->{default}) ? ( $me->{default} ) :
113 0 ▶ length($me->{builder}) ? ( $me->{builder} ) :
Branch: 2 branches
BranchTrueFalseTotal
ref $me->{'default'} ? : 0 0 0
length $me->{'builder'} ? : 0 0 0
114 ();
115 my $callbacks = 'Sub::HandlesVia::Toolkit::Plain'->make_callbacks(
116 $me->{package},
117 0 [ $me->reader, $me->writer, @default ],
118 );
119 0 require Sub::HandlesVia::Handler;
120 0 $me->{handles} = $orig_handles;
121 0 my @pairs = $me->expand_handles;
122 0 ▶ while (@pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 0 0 0
123 0 my ($target, $method) = splice(@pairs, 0, 2);
124 0 my $handler = 'Sub::HandlesVia::Handler'->lookup($method, $shv_data->{handles_via});
125 $me->install_coderef(
126 $target,
127 $handler->coderef(
128 %$callbacks,
129 target => $me->{package},
130 0 ▶ method_name => ref($target) ? '__ANON__' : $target,
Branch: 1 branch
BranchTrueFalseTotal
ref $target ? : 0 0 0
131 ),
132 );
133 }
134 }
135 }
136
137 0 ▶ if (!$shv_data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($shv_data) 0 0 0
138 0 my @pairs = $me->expand_handles;
139 0 ▶ while (@pairs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pairs) 0 0 0
140 0 my ($target, $method) = splice(@pairs, 0, 2);
141 0 $me->install_coderef($target, $me->handles($method));
142 }
143 }
144 }
145
146 my @return = map $$_,
147 $me->{is} eq 'ro' ? ($me->{reader}) :
148 $me->{is} eq 'rw' ? ($me->{accessor}) :
149 $me->{is} eq 'rwp' ? ($me->{reader}, $me->{writer}) :
150 23 ▶ $me->{is} eq 'lazy' ? ($me->{reader}) :
Branch: 4 branches
BranchTrueFalseTotal
$me->{'is'} eq 'ro' ? : 4 19 23
$me->{'is'} eq 'rw' ? : 4 15 19
$me->{'is'} eq 'rwp' ? : 4 11 15
$me->{'is'} eq 'lazy' ? : 4 7 11
151 ();
152 23 ▶ wantarray ? @return : $return[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 19 23
153 }
154  
155 sub install_coderef
156 {
157 44 ▶ my $me = shift;
Subroutine install_coderef: called CC=8 SCAR=24.5
Pod undocumented
158 44 my ($target, $coderef) = @_;
159
160 44 ▶ return unless defined $target;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $target 0 44 44
161
162 44 ▶ if (!ref $target and $target =~ /\A[^\W0-9]\w+\z/)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $target and $target =~ /\A[^\W0-9]\w+\z/) 2 42 44
Condition66%2/3
not ref $target and $target =~ /\A[^\W0-9]\w+\z/
!ll&&!rl&&r
4202
MC/DC50%1/2
not ref $target and $target =~ /\A[^\W0-9]\w+\z/
not ref $target $target =~ /\A[^\W0-9]\w+\z/
Truth table66%2/3
not(A) and B
A= not ref $targetB= $target =~ /\A[^\W0-9]\w+\z/
ABresult
0X0
100
111
163 {
164 2 my $name = "$me->{package}\::$target";
165 2 HAS_SUB_UTIL ? ($coderef = Sub::Util::set_subname($name, $coderef)) :
166 HAS_SUB_NAME ? ($coderef = Sub::Name::subname($name, $coderef)) :
167 ();
168 8 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
169 2 *$name = $coderef;
170 2 return;
171 }
172
173 42 ▶ if (ref($target) eq q(SCALAR) and not defined $$target)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $target eq "SCALAR" and not defined $$target) 42 0 42
Condition33%1/3
ref $target eq "SCALAR" and not defined $$target
!ll&&!rl&&r
0042
MC/DC0%0/2
ref $target eq "SCALAR" and not defined $$target
ref $target eq "SCALAR" not defined $$target
Truth table33%1/3
A and not(B)
A= ref $target eq "SCALAR"B= not defined $$target
ABresult
0X0
100
111
174 {
175 42 $$target = $coderef;
176 42 return;
177 }
178
179 0 ▶ if (!ref($target) and $target eq 1)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $target and $target eq 1) 0 0 0
Condition0%0/3
not ref $target and $target eq 1
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $target and $target eq 1
not ref $target $target eq 1
Truth table0%0/3
not(A) and B
A= not ref $targetB= $target eq 1
ABresult
0X0
100
111
180 {
181 0 return;
182 }
183
184 0 croak "Expected installation target to be a reference to an undefined scalar; got $target";
185 }
186  
187 sub expand_handles
188 {
189 0 ▶ my $me = shift;
Subroutine expand_handles: not called CC=3 SCAR=24.8
Pod undocumented
190
191 0 ▶ if (ref($me->{handles}) eq q(ARRAY))
Branch: 2 branches
BranchTrueFalseTotal
if (ref $me->{'handles'} eq 'ARRAY') { } 0 0 0
elsif (ref $me->{'handles'} eq 'HASH') { } 0 0 0
192 {
193 0 return map ($_=>$_), @{$me->{handles}};
194 }
195 elsif (ref($me->{handles}) eq q(HASH))
196 {
197 0 return %{$me->{handles}};
198 }
199
200 0 croak "Expected delegations to be a reference to an array or hash; got $me->{handles}";
201 }
202  
203 {
204 8 my %one = (
205 accessor => [qw/ %s %s /],
206 reader => [qw/ get_%s _get%s /],
207 writer => [qw/ set_%s _set%s /],
208 predicate => [qw/ has_%s _has%s /],
209 clearer => [qw/ clear_%s _clear%s /],
210 trigger => [qw/ _trigger_%s _trigger_%s /],
211 builder => [qw/ _builder_%s _builder_%s /],
212 );
213
214 sub canonicalize_1 : method
215 {
216 24 ▶ my $me = shift;
Subroutine canonicalize_1: called CC=7 SCAR=21.8
Pod undocumented
217
218 24 ▶ my $is_private = ($me->{slot} =~ /\A_/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$me->{'slot'} =~ /\A_/ ? : 0 24 24
219
220 24 for my $type (keys %one)
221 {
222 168 ▶ next if !exists($me->{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{$type} 120 48 168
223 48 ▶ next if ref($me->{$type});
Branch: 1 branch
BranchTrueFalseTotal
if ref $me->{$type} 46 2 48
224 2 ▶ next if $me->{$type} ne 1;
Branch: 1 branch
BranchTrueFalseTotal
if $me->{$type} ne 1 2 0 2
225
226 croak("Cannot interpret $type=>1 because attribute has no name defined")
227 0 ▶ if !defined $me->{slot};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $me->{"slot"} 0 0 0
228
229 0 $me->{$type} = sprintf($one{$type}[$is_private], $me->{slot});
230 }
231 }
232
233 sub canonicalize_builder : method
234 {
235 24 ▶ my $me = shift;
Subroutine canonicalize_builder: called CC=5 SCAR=28.5
Pod undocumented
236 24 my $name = $me->{slot};
237
238 24 ▶ if (ref $me->{builder} eq 'CODE')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $me->{"builder"} eq "CODE") 0 24 24
239 {
240 HAS_SUB_UTIL or
241 HAS_SUB_NAME or
242 0 do { require Sub::Util };
243
244 0 my $code = $me->{builder};
245 defined($name) && defined($me->{package})
246 0 ▶ or croak("Invalid builder; expected method name as string");
Branch: 1 branch
BranchTrueFalseTotal
defined $name and defined $me->{"package"} or croak("Invalid builder; expected method name as string") 0 0 0
Condition0%0/3
defined $name and defined $me->{"package"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and defined $me->{"package"}
defined $name defined $me->{"package"}
Truth table0%0/3
A and B
A= defined $nameB= defined $me->{"package"}
ABresult
0X0
100
111
247
248 0 ▶ my $is_private = ($name =~ /\A_/) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /\A_/ ? : 0 0 0
249
250 0 my $subname = sprintf($one{builder}[$is_private], $name);
251 0 my $fq_subname = "$me->{package}\::$name";
252 $me->_exporter_install_sub(
253 $subname,
254 {},
255 $me->{_export},
256 0 Sub::Name::subname($fq_subname, $code),
257 );
258 }
259 }
260 }
261  
262 8 sub canonicalize_is : method
263 {
264 2 ▶ my $me = shift;
Subroutine canonicalize_is: called CC=18 SCAR=54.1
Pod undocumented
265 2 my $name = $me->{slot};
266
267 2 ▶ if ($me->{is} eq 'rw')
Branch: 4 branches
BranchTrueFalseTotal
if ($me->{'is'} eq 'rw') { } 0 2 2
elsif ($me->{'is'} eq 'ro') { } 0 2 2
elsif ($me->{'is'} eq 'rwp') { } 0 2 2
elsif ($me->{'is'} eq 'lazy') { } 0 2 2
268 {
269 $me->{accessor} = $name
270 0 ▶ if !exists($me->{accessor}) and defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"accessor"} and defined $name 0 0 0
Condition0%0/3
not exists $me->{"accessor"} and defined $name
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $me->{"accessor"} and defined $name
not exists $me->{"accessor"} defined $name
Truth table0%0/3
not(A) and B
A= not exists $me->{"accessor"}B= defined $name
ABresult
0X0
100
111
271 }
272 elsif ($me->{is} eq 'ro')
273 {
274 $me->{reader} = $name
275 0 ▶ if !exists($me->{reader}) and defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"reader"} and defined $name 0 0 0
Condition0%0/3
not exists $me->{"reader"} and defined $name
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $me->{"reader"} and defined $name
not exists $me->{"reader"} defined $name
Truth table0%0/3
not(A) and B
A= not exists $me->{"reader"}B= defined $name
ABresult
0X0
100
111
276 }
277 elsif ($me->{is} eq 'rwp')
278 {
279 $me->{reader} = $name
280 0 ▶ if !exists($me->{reader}) and defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"reader"} and defined $name 0 0 0
Condition0%0/3
not exists $me->{"reader"} and defined $name
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $me->{"reader"} and defined $name
not exists $me->{"reader"} defined $name
Truth table0%0/3
not(A) and B
A= not exists $me->{"reader"}B= defined $name
ABresult
0X0
100
111
281 $me->{writer} = "_set_$name"
282 0 ▶ if !exists($me->{writer}) and defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"writer"} and defined $name 0 0 0
Condition0%0/3
not exists $me->{"writer"} and defined $name
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $me->{"writer"} and defined $name
not exists $me->{"writer"} defined $name
Truth table0%0/3
not(A) and B
A= not exists $me->{"writer"}B= defined $name
ABresult
0X0
100
111
283 }
284 elsif ($me->{is} eq 'lazy')
285 {
286 $me->{reader} = $name
287 0 ▶ if !exists($me->{reader}) and defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if not exists $me->{"reader"} and defined $name 0 0 0
Condition0%0/3
not exists $me->{"reader"} and defined $name
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $me->{"reader"} and defined $name
not exists $me->{"reader"} defined $name
Truth table0%0/3
not(A) and B
A= not exists $me->{"reader"}B= defined $name
ABresult
0X0
100
111
288 $me->{lazy} = 1
289 0 ▶ if !exists($me->{lazy});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"lazy"} 0 0 0
290 $me->{builder} = 1
291 0 ▶ unless $me->{builder} || $me->{default};
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"builder"} or $me->{"default"} 0 0 0
Condition0%0/3
$me->{"builder"} or $me->{"default"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$me->{"builder"} or $me->{"default"}
$me->{"builder"} $me->{"default"}
Truth table0%0/3
A or B
A= $me->{"builder"}B= $me->{"default"}
ABresult
1X1
011
000
292 }
293 }
294  
295 sub canonicalize_default : method
296 {
297 24 ▶ my $me = shift;
Subroutine canonicalize_default: called CC=4 SCAR=15.9
Pod undocumented
298 24 ▶ return unless exists $me->{default};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $me->{"default"} 19 5 24
299
300 5 ▶ unless (ref $me->{default})
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $me->{"default"}) 0 5 5
301 {
302 0 my $value = $me->{default};
303 0 ▶ $me->{default} = sub { $value };
Subroutine __ANON__: not called CC=1 SCAR=6.9
304 }
305
306 croak("Invalid default; expected a CODE ref")
307 5 ▶ unless ref $me->{default} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $me->{"default"} eq "CODE" 0 5 5
308 }
309  
310 sub canonicalize_isa : method
311 {
312 24 ▶ my $me = shift;
Subroutine canonicalize_isa: called CC=7 SCAR=32.3
Pod undocumented
313
314 24 ▶ if (my $does = $me->{does})
Branch: 1 branch
BranchTrueFalseTotal
if (my $does = $me->{"does"}) 0 24 24
315 {
316 0 ▶ $me->{isa} ||= sub { blessed($_[0]) && $_[0]->DOES($does) };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_[0]) and $_[0]->DOES($does) 0 0 0
Condition0%0/3
$me->{"isa"} ||= sub {
l!l&&r!l&&!r
000
MC/DC0%0/2
$me->{"isa"} ||= sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
$me->{"isa"} sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
Truth table0%0/3
A ||= B
A= $me->{"isa"}B= sub { builtin::blessed($_[0]) and $_[0]->DOES($does); }
ABresult
1X1
011
000
317 }
318
319 24 ▶ if (defined $me->{isa} and not ref $me->{isa})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"isa"} and not ref $me->{"isa"}) 0 24 24
Condition66%2/3
defined $me->{"isa"} and not ref $me->{"isa"}
!ll&&!rl&&r
1950
MC/DC0%0/2
defined $me->{"isa"} and not ref $me->{"isa"}
defined $me->{"isa"} not ref $me->{"isa"}
Truth table66%2/3
A and not(B)
A= defined $me->{"isa"}B= not ref $me->{"isa"}
ABresult
0X0
100
111
320 {
321 0 my $type_name = $me->{isa};
322 0 ▶ eval { require Type::Utils }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Type::Utils } } or croak("Missing requirement; type constraint strings require Type::Utils") 0 0 0
323 or croak("Missing requirement; type constraint strings require Type::Utils");
324
325 $me->{isa} = $me->{package}
326 ? Type::Utils::dwim_type($type_name, for => $me->{package})
327 0 ▶ : Type::Utils::dwim_type($type_name);
Branch: 1 branch
BranchTrueFalseTotal
$me->{'package'} ? : 0 0 0
328 }
329 }
330  
331 sub canonicalize_trigger : method
332 {
333 24 ▶ my $me = shift;
Subroutine canonicalize_trigger: called CC=3 SCAR=15.0
Pod undocumented
334
335 24 ▶ if (defined $me->{trigger} and not ref $me->{trigger})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $me->{"trigger"} and not ref $me->{"trigger"}) 0 24 24
Condition66%2/3
defined $me->{"trigger"} and not ref $me->{"trigger"}
!ll&&!rl&&r
2040
MC/DC0%0/2
defined $me->{"trigger"} and not ref $me->{"trigger"}
defined $me->{"trigger"} not ref $me->{"trigger"}
Truth table66%2/3
A and not(B)
A= defined $me->{"trigger"}B= not ref $me->{"trigger"}
ABresult
0X0
100
111
336 {
337 0 my $method_name = $me->{trigger};
338 0 ▶ $me->{trigger} = sub { my $self = shift; $self->$method_name(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
339 }
340 }
341  
342 sub canonicalize_opts : method
343 {
344 24 ▶ my $me = shift;
Subroutine canonicalize_opts: called CC=4 SCAR=14.1
Pod undocumented
345
346 24 ▶ croak("Initializers are not supported") if $me->{initializer};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"initializer"} 0 24 24
347 24 ▶ croak("Traits are not supported") if $me->{traits};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"traits"} 0 24 24
348 24 ▶ croak("The lazy_build option is not supported") if $me->{lazy_build};
Branch: 1 branch
BranchTrueFalseTotal
if $me->{"lazy_build"} 0 24 24
349
350 24 $me->canonicalize_1;
351 24 $me->canonicalize_is;
352 24 $me->canonicalize_isa;
353 24 $me->canonicalize_default;
354 24 $me->canonicalize_builder;
355 24 $me->canonicalize_trigger;
356 }
357  
358 sub accessor_kind : method
359 {
360 2 ▶ return 'small';
Subroutine accessor_kind: called CC=1 SCAR=0.0
Pod undocumented
361 }
362  
363 sub inline_to_coderef : method
364 {
365 44 ▶ my $me = shift;
Subroutine inline_to_coderef: called CC=2 SCAR=7.0
Pod undocumented
366 44 my ($method_type, $code) = @_;
367  
368 44 my $kind = $me->accessor_kind;
369 44 my $src = sprintf(q[sub { %s }], $code);
370 my $desc = defined($me->{slot})
371 ? sprintf('%s %s for %s', $kind, $method_type, $me->{slot})
372 44 ▶ : sprintf('%s %s', $kind, $method_type);
Branch: 1 branch
BranchTrueFalseTotal
defined $me->{'slot'} ? : 44 0 44
373 # warn "#### $desc\n$src\n";
374
375 return Eval::TypeTiny::eval_closure(
376 source => $src,
377 environment => $me->{inline_environment},
378 44 description => $desc,
379 );
380 }
381  
382 sub clearer : method
383 {
384 4 ▶ my $me = shift;
Subroutine clearer: called CC=1 SCAR=0.0
Pod undocumented
385
386 4 $me->inline_to_coderef(
387 clearer => $me->inline_clearer,
388 );
389 }
390  
391 sub inline_clearer : method
392 {
393 4 ▶ my $me = shift;
Subroutine inline_clearer: called CC=1 SCAR=0.0
Pod undocumented
394
395 4 sprintf(
396 q[ delete(%s) ],
397 $me->inline_access,
398 );
399 }
400  
401 sub inline_access : method
402 {
403 85 ▶ my $me = shift;
Subroutine inline_access: called CC=1 SCAR=0.0
Pod undocumented
404
405 sprintf(
406 q[ $Sub::Accessor::Small::FIELDS{$_[0]}{%d} ],
407 $me->{id},
408 85 );
409 }
410  
411 sub inline_access_w : method
412 {
413 25 ▶ my $me = shift;
Subroutine inline_access_w: called CC=1 SCAR=0.0
Pod undocumented
414 25 my ($expr) = @_;
415
416 25 sprintf(
417 q[ %s = %s ],
418 $me->inline_access,
419 $expr,
420 );
421 }
422  
423 sub predicate : method
424 {
425 4 ▶ my $me = shift;
Subroutine predicate: called CC=1 SCAR=0.0
Pod undocumented
426
427 4 $me->inline_to_coderef(
428 predicate => $me->inline_predicate,
429 );
430 }
431  
432 sub inline_predicate : method
433 {
434 9 ▶ my $me = shift;
Subroutine inline_predicate: called CC=1 SCAR=0.0
Pod undocumented
435
436 9 sprintf(
437 q[ exists(%s) ],
438 $me->inline_access,
439 );
440 }
441  
442 sub handles : method
443 {
444 0 ▶ my $me = shift;
Subroutine handles: not called CC=1 SCAR=6.9
Pod undocumented
445 0 my ($method) = @_;
446
447 0 $me->inline_to_coderef(
448 'delegated method' => $me->inline_handles,
449 );
450 }
451  
452 8 my $handler_uniq = 0;
453 sub inline_handles : method
454 {
455 0 ▶ my $me = shift;
Subroutine inline_handles: not called CC=2 SCAR=17.9
Pod undocumented
456 0 my ($method) = @_;
457
458 0 my $get = $me->inline_access;
459
460 0 my $varname = sprintf('$handler_%d', ++$handler_uniq);
461 0 $me->{inline_environment}{$varname} = \($method);
462
463 0 my $death = 'Scalar::Util::blessed($h) or Carp::croak("Expected blessed object to delegate to; got $h")';
464
465 0 ▶ if (ref $method eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $method eq 'ARRAY') { } 0 0 0
466 {
467 0 return sprintf(
468 q[ %s; my $h = %s; %s; shift; my ($m, @a) = @%s; $h->$m(@a, @_) ],
469 $me->inline_default,
470 $get,
471 $death,
472 $varname,
473 );
474 }
475 else
476 {
477 0 return sprintf(
478 q[ %s; my $h = %s; %s; shift; $h->%s(@_) ],
479 $me->inline_default,
480 $get,
481 $death,
482 $varname,
483 );
484 }
485 }
486  
487 sub inline_get : method
488 {
489 28 ▶ my $me = shift;
Subroutine inline_get: called CC=2 SCAR=7.4
Pod undocumented
490
491 28 my $get = $me->inline_access;
492
493 28 ▶ if ($me->{auto_deref})
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"auto_deref"}) 0 28 28
494 {
495 0 $get = sprintf(
496 q[ do { my $x = %s; wantarray ? (ref($x) eq 'ARRAY' ? @$x : ref($x) eq 'HASH' ? %$x : $x ) : $x } ],
497 $get,
498 );
499 }
500
501 28 return $get;
502 }
503  
504 sub inline_default : method
505 {
506 21 ▶ my $me = shift;
Subroutine inline_default: called CC=4 SCAR=14.8
Pod undocumented
507
508 21 ▶ if ($me->{lazy})
Branch: 1 branch
BranchTrueFalseTotal
if ($me->{"lazy"}) 5 16 21
509 {
510 5 my $get = $me->inline_access;
511
512 5 ▶ if ($me->{default})
Branch: 2 branches
BranchTrueFalseTotal
if ($me->{'default'}) { } 5 0 5
elsif (defined $me->{'builder'}) { } 0 0 0
513 {
514 5 $me->{inline_environment}{'$default'} = \($me->{default});
515
516 5 return sprintf(
517 q[ %s unless %s; ],
518 $me->inline_access_w( q[$default->($_[0])] ),
519 $me->inline_predicate,
520 );
521 }
522 elsif (defined $me->{builder})
523 {
524 return sprintf(
525 q[ %s unless %s; ],
526 0 $me->inline_access_w( q($_[0]->) . $me->{builder} ),
527 $me->inline_predicate,
528 );
529 }
530 }
531
532 16 return '';
533 }
534  
535 sub reader : method
536 {
537 16 ▶ my $me = shift;
Subroutine reader: called CC=1 SCAR=0.0
Pod undocumented
538
539 16 $me->inline_to_coderef(
540 reader => $me->inline_reader,
541 );
542 }
543  
544 sub inline_reader : method
545 {
546 21 ▶ my $me = shift;
Subroutine inline_reader: called CC=1 SCAR=0.0
Pod undocumented
547
548 21 join('',
549 $me->inline_default,
550 $me->inline_get,
551 );
552 }
553  
554 sub writer : method
555 {
556 8 ▶ my $me = shift;
Subroutine writer: called CC=1 SCAR=0.0
Pod undocumented
557
558 8 $me->inline_to_coderef(
559 writer => $me->inline_writer,
560 );
561 }
562  
563 sub inline_writer : method
564 {
565 8 ▶ my $me = shift;
Subroutine inline_writer: called CC=4 SCAR=14.6
Pod undocumented
566
567 8 my $get = $me->inline_access;
568 8 my $coerce = $me->inline_type_coercion('$_[1]');
569
570 8 ▶ if ($coerce eq '$_[1]') # i.e. no coercion
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce eq "\$_[1]") 4 4 8
571 {
572 4 ▶ if (!$me->{trigger} and !$me->{weak_ref})
Branch: 1 branch
BranchTrueFalseTotal
unless ($me->{"trigger"} or $me->{"weak_ref"}) 4 0 4
Condition33%1/3
$me->{"trigger"} or $me->{"weak_ref"}
l!l&&r!l&&!r
004
MC/DC0%0/2
$me->{"trigger"} or $me->{"weak_ref"}
$me->{"trigger"} $me->{"weak_ref"}
Truth table33%1/3
A or B
A= $me->{"trigger"}B= $me->{"weak_ref"}
ABresult
1X1
011
000
573 {
574 4 return $me->inline_access_w(
575 $me->inline_type_assertion('$_[1]'),
576 );
577 }
578
579 0 return sprintf(
580 '%s; %s; %s; %s; %s',
581 $me->inline_type_assertion('$_[1]'),
582 $me->inline_trigger('$_[1]', $get),
583 $me->inline_access_w('$_[1]'),
584 $me->inline_weaken,
585 $me->inline_get,
586 );
587 }
588
589 sprintf(
590 4 'my $val = %s; %s; %s; %s; %s; $val',
591 $coerce,
592 $me->inline_type_assertion('$val'),
593 $me->inline_trigger('$val', $get),
594 $me->inline_access_w('$val'),
595 $me->inline_weaken,
596 );
597 }
598  
599 sub accessor : method
600 {
601 12 ▶ my $me = shift;
Subroutine accessor: called CC=1 SCAR=0.0
Pod undocumented
602
603 12 $me->inline_to_coderef(
604 accessor => $me->inline_accessor,
605 );
606 }
607  
608 sub inline_accessor : method
609 {
610 12 ▶ my $me = shift;
Subroutine inline_accessor: called CC=5 SCAR=16.2
Pod undocumented
611  
612 12 my $get = $me->inline_access;
613 12 my $coerce = $me->inline_type_coercion('$_[1]');
614
615 12 ▶ if ($coerce eq '$_[1]') # i.e. no coercion
Branch: 1 branch
BranchTrueFalseTotal
if ($coerce eq "\$_[1]") 8 4 12
616 {
617 8 ▶ if (!$me->{lazy} and !$me->{trigger} and !$me->{weak_ref})
Branch: 1 branch
BranchTrueFalseTotal
unless ($me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}) 7 1 8
Condition66%4/6
$me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}
l!l&&r!l&&!r
107
$me->{"lazy"} or $me->{"trigger"}
l!l&&r!l&&!r
107
MC/DC33%1/3
$me->{"lazy"} or $me->{"trigger"} or $me->{"weak_ref"}
$me->{"lazy"} $me->{"trigger"} $me->{"weak_ref"}
Truth table50%2/4
A or B or C
A= $me->{"lazy"}B= $me->{"trigger"}C= $me->{"weak_ref"}
ABCresult
1XX1
01X1
0011
0000
618 {
619 7 return sprintf(
620 '(@_ > 1) ? (%s) : %s',
621 $me->inline_access_w( $me->inline_type_assertion('$_[1]') ),
622 $me->inline_get,
623 );
624 }
625
626 1 return sprintf(
627 'if (@_ > 1) { %s; %s; %s; %s }; %s',
628 $me->inline_type_assertion('$_[1]'),
629 $me->inline_trigger('$_[1]', $get),
630 $me->inline_access_w('$_[1]'),
631 $me->inline_weaken,
632 $me->inline_reader,
633 );
634 }
635
636 sprintf(
637 4 'if (@_ > 1) { my $val = %s; %s; %s; %s; %s }; %s',
638 $coerce,
639 $me->inline_type_assertion('$val'),
640 $me->inline_trigger('$val', $get),
641 $me->inline_access_w('$val'),
642 $me->inline_weaken,
643 $me->inline_reader,
644 );
645 }
646  
647 sub inline_type_coercion : method
648 {
649 20 ▶ my $me = shift;
Subroutine inline_type_coercion: called CC=14 SCAR=40.6
Pod undocumented
650 20 my ($var) = @_;
651
652 20 ▶ my $coercion = $me->{coerce} or return $var;
Branch: 1 branch
BranchTrueFalseTotal
my $coercion = $me->{"coerce"} or return $var 12 8 20
653
654 8 ▶ unless (ref $coercion)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $coercion) 8 0 8
655 {
656 8 my $type = $me->{isa};
657
658 8 ▶ if (blessed($type) and $type->can('coercion'))
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can('coercion')) { } 8 0 8
elsif (builtin::blessed($type) and $type->can('coerce')) { } 0 0 0
Condition33%1/3
builtin::blessed($type) and $type->can("coercion")
!ll&&!rl&&r
008
MC/DC0%0/2
builtin::blessed($type) and $type->can("coercion")
builtin::blessed($type) $type->can("coercion")
Truth table33%1/3
A and B
A= builtin::blessed($type)B= $type->can("coercion")
ABresult
0X0
100
111
659 {
660 8 $coercion = $type->coercion;
661 }
662 ▶ elsif (blessed($type) and $type->can('coerce'))
Condition0%0/3
builtin::blessed($type) and $type->can("coerce")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($type) and $type->can("coerce")
builtin::blessed($type) $type->can("coerce")
Truth table0%0/3
A and B
A= builtin::blessed($type)B= $type->can("coerce")
ABresult
0X0
100
111
663 {
664 0 ▶ $coercion = sub { $type->coerce(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
665 }
666 else
667 {
668 0 croak("Invalid coerce; type constraint cannot be probed for coercion");
669 }
670
671 8 ▶ unless (ref $coercion)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $coercion) 0 8 8
672 {
673 0 carp("Invalid coerce; type constraint has no coercion");
674 0 return $var;
675 }
676 }
677
678 8 ▶ if ( blessed($coercion)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")) 8 0 8
Condition33%3/9
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")
!ll&&!rl&&r
008
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined
!ll&&!rl&&r
008
builtin::blessed($coercion) and $coercion->can("can_be_inlined")
!ll&&!rl&&r
008
MC/DC0%0/4
builtin::blessed($coercion) and $coercion->can("can_be_inlined") and $coercion->can_be_inlined and $coercion->can("inline_coercion")
builtin::blessed($coercion) $coercion->can("can_be_inlined") $coercion->can_be_inlined $coercion->can("inline_coercion")
Truth table20%1/5
A and B and C and D
A= builtin::blessed($coercion)B= $coercion->can("can_be_inlined")C= $coercion->can_be_inlinedD= $coercion->can("inline_coercion")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
679 and $coercion->can('can_be_inlined')
680 and $coercion->can_be_inlined
681 and $coercion->can('inline_coercion') )
682 {
683 8 return $coercion->inline_coercion($var);
684 }
685
686 # Otherwise need to close over $coerce
687 0 $me->{inline_environment}{'$coercion'} = \$coercion;
688
689 0 ▶ if ( blessed($coercion)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($coercion) and $coercion->can("coerce")) 0 0 0
Condition0%0/3
builtin::blessed($coercion) and $coercion->can("coerce")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($coercion) and $coercion->can("coerce")
builtin::blessed($coercion) $coercion->can("coerce")
Truth table0%0/3
A and B
A= builtin::blessed($coercion)B= $coercion->can("coerce")
ABresult
0X0
100
111
690 and $coercion->can('coerce') )
691 {
692 0 return sprintf('$coercion->coerce(%s)', $var);
693 }
694
695 0 return sprintf('$coercion->(%s)', $var);
696 }
697  
698 sub inline_type_assertion : method
699 {
700 20 ▶ my $me = shift;
Subroutine inline_type_assertion: called CC=14 SCAR=45.2
Pod undocumented
701 20 my ($var) = @_;
702
703 20 ▶ my $type = $me->{isa} or return $var;
Branch: 1 branch
BranchTrueFalseTotal
my $type = $me->{"isa"} or return $var 11 9 20
704
705 9 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined) 9 0 9
Condition33%2/6
builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined
!ll&&!rl&&r
009
builtin::blessed($type) and $type->isa("Type::Tiny")
!ll&&!rl&&r
009
MC/DC0%0/3
builtin::blessed($type) and $type->isa("Type::Tiny") and $type->can_be_inlined
builtin::blessed($type) $type->isa("Type::Tiny") $type->can_be_inlined
Truth table25%1/4
A and B and C
A= builtin::blessed($type)B= $type->isa("Type::Tiny")C= $type->can_be_inlined
ABCresult
0XX0
10X0
1100
1111
706 and $type->isa('Type::Tiny')
707 and $type->can_be_inlined )
708 {
709 9 my $ass = $type->inline_assert($var);
710 9 ▶ if ($ass =~ /\Ado \{(.+)\};\z/sm)
Branch: 1 branch
BranchTrueFalseTotal
if ($ass =~ /\Ado \{(.+)\};\z/ms) 9 0 9
711 {
712 9 return "do { $1 }"; # i.e. drop trailing ";"
713 }
714 # otherwise protect expression from trailing ";"
715 0 return "do { $ass }"
716 }
717
718 # Otherwise need to close over $type
719 0 $me->{inline_environment}{'$type'} = \$type;
720
721 # non-Type::Tiny but still supports inlining
722 0 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined) 0 0 0
Condition0%0/6
builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined
!ll&&!rl&&r
000
builtin::blessed($type) and $type->can("can_be_inlined")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($type) and $type->can("can_be_inlined") and $type->can_be_inlined
builtin::blessed($type) $type->can("can_be_inlined") $type->can_be_inlined
Truth table0%0/4
A and B and C
A= builtin::blessed($type)B= $type->can("can_be_inlined")C= $type->can_be_inlined
ABCresult
0XX0
10X0
1100
1111
723 and $type->can('can_be_inlined')
724 and $type->can_be_inlined )
725 {
726 0 ▶ my $inliner = $type->can('inline_check') || $type->can('_inline_check');
Condition0%0/3
$type->can('inline_check') || $type->can('_inline_check')
l!l&&r!l&&!r
000
MC/DC0%0/2
$type->can('inline_check') || $type->can('_inline_check')
$type->can('inline_check') $type->can('_inline_check')
Truth table0%0/3
A || B
A= $type->can('inline_check')B= $type->can('_inline_check')
ABresult
1X1
011
000
727 0 ▶ if ($inliner)
Branch: 1 branch
BranchTrueFalseTotal
if ($inliner) 0 0 0
728 {
729 0 return sprintf('do { %s } ? %s : Carp::croak($type->get_message(%s))', $type->$inliner($var), $var, $var);
730 }
731 }
732
733 0 ▶ if ( blessed($type)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type) and $type->can("check") and $type->can("get_message")) 0 0 0
Condition0%0/6
builtin::blessed($type) and $type->can("check") and $type->can("get_message")
!ll&&!rl&&r
000
builtin::blessed($type) and $type->can("check")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($type) and $type->can("check") and $type->can("get_message")
builtin::blessed($type) $type->can("check") $type->can("get_message")
Truth table0%0/4
A and B and C
A= builtin::blessed($type)B= $type->can("check")C= $type->can("get_message")
ABCresult
0XX0
10X0
1100
1111
734 and $type->can('check')
735 and $type->can('get_message') )
736 {
737 0 return sprintf('$type->check(%s) ? %s : Carp::croak($type->get_message(%s))', $var, $var, $var);
738 }
739
740 0 return sprintf('$type->(%s) ? %s : Carp::croak("Value %s failed type constraint check")', $var, $var, $var);
741 }
742  
743 sub inline_weaken : method
744 {
745 9 ▶ my $me = shift;
Subroutine inline_weaken: called CC=2 SCAR=8.1
Pod undocumented
746
747 9 ▶ return '' unless $me->{weak_ref};
Branch: 1 branch
BranchTrueFalseTotal
unless $me->{"weak_ref"} 9 0 9
748
749 0 sprintf(
750 q[ Scalar::Util::weaken(%s) if ref(%s) ],
751 $me->inline_access,
752 $me->inline_access,
753 );
754 }
755  
756 sub inline_trigger : method
757 {
758 9 ▶ my $me = shift;
Subroutine inline_trigger: called CC=2 SCAR=6.9
Pod undocumented
759 9 my ($new, $old) = @_;
760
761 9 ▶ my $trigger = $me->{trigger} or return '';
Branch: 1 branch
BranchTrueFalseTotal
my $trigger = $me->{"trigger"} or return "" 1 8 9
762
763 8 $me->{inline_environment}{'$trigger'} = \$trigger;
764 8 return sprintf('$trigger->($_[0], %s, %s)', $new, $old);
765 }
766  
767 8 1;
768  
769 __END__
770  
771 =pod
772  
773 =encoding utf-8
774  
775 =for stopwords benchmarking
776  
777 =head1 NAME
778  
779 Sub::Accessor::Small - small toolkit for generating getter/setter methods
780  
781 =head1 SYNOPSIS
782  
783 package MyClass;
784 use Sub::Accessor::Small;
785 use Types::Standard qw( Int );
786
787 sub new {
788 my $class = shift;
789 my $self = bless \$class, $class;
790 my %args = @_ == 1 ? %{ $_[0] } : @_;
791
792 # Simple way to initialize each attribute
793 for my $key ( sort keys %args ) {
794 $self->$key( $args{$key} );
795 }
796
797 return $self;
798 }
799
800 'Sub::Accessor::Small'->new(
801 package => __PACKAGE__,
802 name => "foo",
803 is => "rw",
804 isa => Int,
805 )->install_accessors();
806
807 package main;
808
809 my $obj = MyClass->new( foo => 42 );
810  
811 =head1 DESCRIPTION
812  
813 This is a small toolkit for generating Moose-like attribute accessors.
814 B<< It does not generate a constructor. >>
815  
816 It stores attribute values inside-out, but it is designed for
817 Sub::Accessor::Small to be subclassed, making it easy to store attributes
818 in other ways.
819  
820 =head1 BUGS
821  
822 Please report any bugs to
823 L<http://rt.cpan.org/Dist/Display.html?Queue=Lexical-Accessor>.
824  
825 =head1 SEE ALSO
826  
827 L<Lexical::Accessor>.
828  
829 =head1 AUTHOR
830  
831 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
832  
833 =head1 COPYRIGHT AND LICENCE
834  
835 This software is copyright (c) 2013-2014, 2017, 2020 by Toby Inkster.
836  
837 This is free software; you can redistribute it and/or modify it under
838 the same terms as the Perl 5 programming language system itself.
839  
840 =head1 DISCLAIMER OF WARRANTIES
841  
842 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
843 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
844 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
845  
↑ Summary Lexical/Accessor.pm »