blib/lib/Class/MOP/Attribute.pm

filter: Statementstmt 97.8% 183 / 187 Branchbran 96.0% 73 / 76 Conditioncond 87.5% 42 / 48 MC/DCmcdc 65.5% 19 / 29 Subroutinesub 100% 46 / 46 Podpod 100% 20 / 20 totaltotal 94.3% 383 / 406 CC 55 SCAR 16.2
CC
55
Cov
96%
new
15.0
__ANON__
6.3
initialize_instance_slot
6.0
CRAP 5.1
« blib/lib/Moose/Meta/Class.pm ↑ Summary blib/lib/Moose/Meta/Role/Application/ToClass.pm »
1 package Class::MOP::Attribute;
2 459 our $VERSION = '2.4001';
3  
4 459 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 459 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 459 ▶use Class::MOP::Method::Accessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 459 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 459 ▶use Scalar::Util 'blessed', 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 459 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 459 ▶use parent 'Class::MOP::Object', 'Class::MOP::Mixin::AttributeCore';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # NOTE: (meta-circularity)
16 # This method will be replaced in the
17 # boostrap section of Class::MOP, by
18 # a new version which uses the
19 # &Class::MOP::Class::construct_instance
20 # method to build an attribute meta-object
21 # which itself is described with attribute
22 # meta-objects.
23 # - Ain't meta-circularity grand? :)
24 57923 ▶sub new {
Subroutine new: called CC=15 SCAR=27.1
Pod documented
25 57923 my ( $class, @args ) = @_;
26  
27 57923 ▶ unshift @args, "name" if @args % 2 == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 == 1 57920 3 57923
28 57923 my %options = @args;
29  
30 57923 my $name = $options{name};
31  
32 57923 ▶ (defined $name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $class->_throw_exception("MOPAttributeNewNeedsAttributeName", "class", $class, "params", \%options) 57919 4 57923
33 || $class->_throw_exception( MOPAttributeNewNeedsAttributeName => class => $class,
34 params => \%options
35 );
36  
37 $options{init_arg} = $name
38 57919 ▶ if not exists $options{init_arg};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"init_arg"} 53543 4376 57919
39 57919 ▶ if(exists $options{builder}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{'builder'}) { } 482 57437 57919
40 $class->_throw_exception( BuilderMustBeAMethodName => class => $class,
41 params => \%options
42 )
43 482 ▶ if ref $options{builder} || !(defined $options{builder});
Branch: 1 branch
BranchTrueFalseTotal
if ref $options{"builder"} or not defined $options{"builder"} 6 476 482
Condition66%2/3
ref $options{"builder"} or not defined $options{"builder"}
l!l&&r!l&&!r
60476
MC/DC50%1/2
ref $options{"builder"} or not defined $options{"builder"}
ref $options{"builder"} not defined $options{"builder"}
Truth table66%2/3
A or not(B)
A= ref $options{"builder"}B= not defined $options{"builder"}
ABresult
1X1
011
000
44 $class->_throw_exception( BothBuilderAndDefaultAreNotAllowed => class => $class,
45 params => \%options
46 )
47 476 ▶ if exists $options{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"default"} 2 474 476
48 } else {
49 ($class->is_default_a_coderef(\%options))
50 || $class->_throw_exception( ReferencesAreNotAllowedAsDefault => class => $class,
51 params => \%options,
52 attribute_name => $options{name}
53 )
54 57437 ▶ if exists $options{default} && ref $options{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"default"} and ref $options{"default"} 12074 45363 57437
Condition100%7/7
exists $options{'default'} && ref $options{'default'} && ($class->is_default_a_coderef(\%options) || $class->_throw_exception('ReferencesAreNotAllowedAsDefault', 'class', $class, 'params', \%options, 'attribute_name', $options{'name'}))
!ll
4536312074
exists $options{"default"} and ref $options{"default"}
!ll&&!rl&&r
37231813212074
$class->is_default_a_coderef(\%options) or $class->_throw_exception("ReferencesAreNotAllowedAsDefault", "class", $class, "params", \%options, "attribute_name", $options{"name"})
l!l
120668
MC/DC0%0/4
exists $options{'default'} && ref $options{'default'} && ($class->is_default_a_coderef(\%options) || $class->_throw_exception('ReferencesAreNotAllowedAsDefault', 'class', $class, 'params', \%options, 'attribute_name', $options{'name'}))
exists $options{"default"} ref $options{"default"} $class->is_default_a_coderef(\%options) $class->_throw_exception("ReferencesAreNotAllowedAsDefault", "class", $class, "params", \%options, "attribute_name", $options{"name"})
Truth table40%2/5
A and B && C or D
A= exists $options{"default"}B= ref $options{"default"}C= $class->is_default_a_coderef(\%options)D= $class->_throw_exception("ReferencesAreNotAllowedAsDefault", "class", $class, "params", \%options, "attribute_name", $options{"name"})
ABCDresult
0XXX0
10XX0
11000
111X1
11011
55 }
56  
57 57903 ▶ if( $options{required} and not( defined($options{builder}) || defined($options{init_arg}) || exists $options{default} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"required"} and not defined $options{"builder"} || defined $options{"init_arg"} || exists $options{"default"}) 1 57902 57903
Condition88%8/9
$options{"required"} and not defined $options{"builder"} || defined $options{"init_arg"} || exists $options{"default"}
!ll&&!rl&&r
5569322091
defined $options{'builder'} || defined $options{'init_arg'} || exists $options{'default'}
l!l&&r!l&&!r
220901
defined $options{"builder"} or defined $options{"init_arg"}
l!l&&r!l&&!r
422051
MC/DC75%3/4
$options{"required"} and not defined $options{"builder"} || defined $options{"init_arg"} || exists $options{"default"}
$options{"required"} defined $options{"builder"} defined $options{"init_arg"} exists $options{'default'}
Truth table80%4/5
A and not(B or C || D)
A= $options{"required"}B= defined $options{"builder"}C= defined $options{"init_arg"}D= exists $options{'default'}
ABCDresult
0XXX0
11XX0
101X0
10010
10001
58 1 $class->_throw_exception( RequiredAttributeLacksInitialization => class => $class,
59 params => \%options
60 );
61 }
62  
63 57902 $class->_new(\%options);
64 }
65  
66 55605 ▶sub _new {
Subroutine _new: called CC=4 SCAR=13.9
67 55605 my $class = shift;
68  
69 55605 ▶ return Class::MOP::Class->initialize($class)->new_object(@_)
Branch: 1 branch
BranchTrueFalseTotal
if $class ne __PACKAGE__ 420 55185 55605
70 if $class ne __PACKAGE__;
71  
72 55185 ▶ my $options = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 55185 0 55185
73  
74 bless {
75 'name' => $options->{name},
76 'accessor' => $options->{accessor},
77 'reader' => $options->{reader},
78 'writer' => $options->{writer},
79 'predicate' => $options->{predicate},
80 'clearer' => $options->{clearer},
81 'builder' => $options->{builder},
82 'init_arg' => $options->{init_arg},
83 exists $options->{default}
84 ? ('default' => $options->{default})
85 : (),
86 'initializer' => $options->{initializer},
87 'definition_context' => $options->{definition_context},
88 # keep a weakened link to the
89 # class we are associated with
90 55185 ▶ 'associated_class' => undef,
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{'default'} ? : 19873 35312 55185
91 # and a list of the methods
92 # associated with this attr
93 'associated_methods' => [],
94 # this let's us keep track of
95 # our order inside the associated
96 # class
97 'insertion_order' => undef,
98 }, $class;
99 }
100  
101 # NOTE:
102 # this is a primitive (and kludgy) clone operation
103 # for now, it will be replaced in the Class::MOP
104 # bootstrap with a proper one, however we know
105 # that this one will work fine for now.
106 sub clone {
107 my $self = shift;
108 my %options = @_;
109 (blessed($self))
110 || confess "Can only clone an instance";
111 # this implementation is overwritten by the bootstrap process,
112 # so this exception will never trigger. If it ever does occur,
113 # it indicates a gigantic problem with the most internal parts
114 # of Moose, so we wouldn't want a Moose-based exception object anyway
115  
116 return bless { %{$self}, %options } => ref($self);
117 }
118  
119 165175 ▶sub initialize_instance_slot {
Subroutine initialize_instance_slot: called CC=6 SCAR=17.9
Pod documented
120 165175 my ($self, $meta_instance, $instance, $params) = @_;
121 165175 my $init_arg = $self->{'init_arg'};
122  
123 # try to fetch the init arg from the %params ...
124  
125 # if nothing was in the %params, we can use the
126 # attribute's default value (if it has one)
127 165175 ▶ if(defined $init_arg and exists $params->{$init_arg}){
Branch: 3 branches
BranchTrueFalseTotal
if (defined $init_arg and exists $params->{$init_arg}) { } 91683 73492 165175
elsif (exists $self->{'default'}) { } 39263 34229 73492
elsif (defined(my $builder = $self->{'builder'})) { } 9 34220 34229
Condition100%3/3
defined $init_arg and exists $params->{$init_arg}
!ll&&!rl&&r
111456234791683
MC/DC100%2/2
defined $init_arg and exists $params->{$init_arg}
defined $init_arg exists $params->{$init_arg}
Truth table100%3/3
A and B
A= defined $init_argB= exists $params->{$init_arg}
ABresult
0X0
100
111
128 $self->_set_initial_slot_value(
129 $meta_instance,
130 $instance,
131 91683 $params->{$init_arg},
132 );
133 }
134 elsif (exists $self->{'default'}) {
135 39263 $self->_set_initial_slot_value(
136 $meta_instance,
137 $instance,
138 $self->default($instance),
139 );
140 }
141 elsif (defined( my $builder = $self->{'builder'})) {
142 9 ▶ if ($builder = $instance->can($builder)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder = $instance->can($builder)) { } 8 1 9
143 8 $self->_set_initial_slot_value(
144 $meta_instance,
145 $instance,
146 $instance->$builder,
147 );
148 }
149 else {
150 1 $self->_throw_exception( BuilderMethodNotSupportedForAttribute => attribute => $self,
151 instance => $instance
152 );
153 }
154 }
155 }
156  
157 134254 ▶sub _set_initial_slot_value {
Subroutine _set_initial_slot_value: called CC=2 SCAR=6.9
158 134254 my ($self, $meta_instance, $instance, $value) = @_;
159  
160 134254 my $slot_name = $self->name;
161  
162 134254 ▶ return $meta_instance->set_slot_value($instance, $slot_name, $value)
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_initializer 134242 12 134254
163 unless $self->has_initializer;
164  
165 12 my $callback = $self->_make_initializer_writer_callback(
166 $meta_instance, $instance, $slot_name
167 );
168  
169 12 my $initializer = $self->initializer;
170  
171 # most things will just want to set a value, so make it first arg
172 12 $instance->$initializer($value, $callback, $self);
173 }
174  
175 12 ▶sub _make_initializer_writer_callback {
Subroutine _make_initializer_writer_callback: called CC=1 SCAR=0.0
176 12 my $self = shift;
177 12 my ($meta_instance, $instance, $slot_name) = @_;
178  
179 11 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
180 11 $meta_instance->set_slot_value($instance, $slot_name, $_[0]);
181 12 };
182 }
183  
184 244 ▶sub get_read_method {
Subroutine get_read_method: called CC=3 SCAR=11.0
Pod documented
185 244 my $self = shift;
186 244 ▶ my $reader = $self->reader || $self->accessor;
Condition100%3/3
$self->reader || $self->accessor
l!l&&r!l&&!r
11611414
MC/DC100%2/2
$self->reader || $self->accessor
$self->reader $self->accessor
Truth table100%3/3
A || B
A= $self->readerB= $self->accessor
ABresult
1X1
011
000
187 # normal case ...
188 244 ▶ return $reader unless ref $reader;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $reader 209 35 244
189 # the HASH ref case
190 35 my ($name) = %$reader;
191 35 return $name;
192 }
193  
194 121 ▶sub get_write_method {
Subroutine get_write_method: called CC=3 SCAR=11.8
Pod documented
195 121 my $self = shift;
196 121 ▶ my $writer = $self->writer || $self->accessor;
Condition100%3/3
$self->writer || $self->accessor
l!l&&r!l&&!r
58630
MC/DC100%2/2
$self->writer || $self->accessor
$self->writer $self->accessor
Truth table100%3/3
A || B
A= $self->writerB= $self->accessor
ABresult
1X1
011
000
197 # normal case ...
198 121 ▶ return $writer unless ref $writer;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $writer 121 0 121
199 # the HASH ref case
200 0 my ($name) = %$writer;
201 0 return $name;
202 }
203  
204 121 ▶sub get_read_method_ref {
Subroutine get_read_method_ref: called CC=4 SCAR=13.9
Pod documented
205 121 my $self = shift;
206 121 ▶ if ((my $reader = $self->get_read_method) && $self->associated_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reader = $self->get_read_method and $self->associated_class) { } 107 14 121
Condition100%3/3
my $reader = $self->get_read_method and $self->associated_class
!ll&&!rl&&r
122107
MC/DC100%2/2
my $reader = $self->get_read_method and $self->associated_class
my $reader = $self->get_read_method $self->associated_class
Truth table100%3/3
A and B
A= my $reader = $self->get_read_methodB= $self->associated_class
ABresult
0X0
100
111
207 107 return $self->associated_class->get_method($reader);
208 }
209 else {
210 14 ▶ my $code = sub { $self->get_value(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
211 14 ▶ if (my $class = $self->associated_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = $self->associated_class) { } 10 4 14
212 10 return $class->method_metaclass->wrap(
213 $code,
214 package_name => $class->name,
215 name => '__ANON__'
216 );
217 }
218 else {
219 4 return $code;
220 }
221 }
222 }
223  
224 111 ▶sub get_write_method_ref {
Subroutine get_write_method_ref: called CC=4 SCAR=13.9
Pod documented
225 111 my $self = shift;
226 111 ▶ if ((my $writer = $self->get_write_method) && $self->associated_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $writer = $self->get_write_method and $self->associated_class) { } 83 28 111
Condition100%3/3
my $writer = $self->get_write_method and $self->associated_class
!ll&&!rl&&r
26283
MC/DC100%2/2
my $writer = $self->get_write_method and $self->associated_class
my $writer = $self->get_write_method $self->associated_class
Truth table100%3/3
A and B
A= my $writer = $self->get_write_methodB= $self->associated_class
ABresult
0X0
100
111
227 83 return $self->associated_class->get_method($writer);
228 }
229 else {
230 28 ▶ my $code = sub { $self->set_value(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
231 28 ▶ if (my $class = $self->associated_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = $self->associated_class) { } 24 4 28
232 24 return $class->method_metaclass->wrap(
233 $code,
234 package_name => $class->name,
235 name => '__ANON__'
236 );
237 }
238 else {
239 4 return $code;
240 }
241 }
242 }
243  
244 # slots
245  
246 175649 ▶sub slots { (shift)->name }
Subroutine slots: called CC=1 SCAR=0.0
Pod documented
247  
248 # class association
249  
250 57891 ▶sub attach_to_class {
Subroutine attach_to_class: called CC=3 SCAR=11.0
Pod documented
251 57891 my ($self, $class) = @_;
252 57891 ▶ (blessed($class) && $class->isa('Class::MOP::Class'))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($class) and $class->isa("Class::MOP::Class") or $self->_throw_exception("AttachToClassNeedsAClassMOPClassInstanceOrASubclass", "attribute", $self, "class", $class) 57887 4 57891
Condition100%3/3
builtin::blessed($class) and $class->isa("Class::MOP::Class")
!ll&&!rl&&r
3157887
MC/DC100%2/2
builtin::blessed($class) and $class->isa("Class::MOP::Class")
builtin::blessed($class) $class->isa("Class::MOP::Class")
Truth table100%3/3
A and B
A= builtin::blessed($class)B= $class->isa("Class::MOP::Class")
ABresult
0X0
100
111
253 || $self->_throw_exception( AttachToClassNeedsAClassMOPClassInstanceOrASubclass => attribute => $self,
254 class => $class
255 );
256 57887 weaken($self->{'associated_class'} = $class);
257 }
258  
259 26 ▶sub detach_from_class {
Subroutine detach_from_class: called CC=1 SCAR=0.0
Pod documented
260 26 my $self = shift;
261 26 $self->{'associated_class'} = undef;
262 }
263  
264 # method association
265  
266 111469 ▶sub associate_method {
Subroutine associate_method: called CC=1 SCAR=0.0
Pod documented
267 111469 my ($self, $method) = @_;
268 111469 push @{$self->{'associated_methods'}} => $method;
269 }
270  
271 ## Slot management
272  
273 3300 ▶sub set_initial_value {
Subroutine set_initial_value: called CC=1 SCAR=0.0
Pod documented
274 3300 my ($self, $instance, $value) = @_;
275 3300 $self->_set_initial_slot_value(
276 Class::MOP::Class->initialize(ref($instance))->get_meta_instance,
277 $instance,
278 $value
279 );
280 }
281  
282 400 ▶sub set_value { shift->set_raw_value(@_) }
Subroutine set_value: called CC=1 SCAR=0.0
Pod documented
283  
284 401 ▶sub set_raw_value {
Subroutine set_raw_value: called CC=1 SCAR=0.0
Pod documented
285 401 my $self = shift;
286 401 my ($instance, $value) = @_;
287  
288 401 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
289 401 return $mi->set_slot_value($instance, $self->name, $value);
290 }
291  
292 156742 ▶sub _inline_set_value {
Subroutine _inline_set_value: called CC=1 SCAR=0.0
293 156742 my $self = shift;
294 156742 return $self->_inline_instance_set(@_) . ';';
295 }
296  
297 157632 ▶sub _inline_instance_set {
Subroutine _inline_instance_set: called CC=1 SCAR=0.0
298 157632 my $self = shift;
299 157632 my ($instance, $value) = @_;
300  
301 157632 my $mi = $self->associated_class->get_meta_instance;
302 157630 return $mi->inline_set_slot_value($instance, $self->name, $value);
303 }
304  
305 6581 ▶sub get_value { shift->get_raw_value(@_) }
Subroutine get_value: called CC=1 SCAR=0.0
Pod documented
306  
307 6583 ▶sub get_raw_value {
Subroutine get_raw_value: called CC=1 SCAR=0.0
Pod documented
308 6583 my $self = shift;
309 6583 my ($instance) = @_;
310  
311 6583 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
312 6583 return $mi->get_slot_value($instance, $self->name);
313 }
314  
315 29574 ▶sub _inline_get_value {
Subroutine _inline_get_value: called CC=1 SCAR=0.0
316 29574 my $self = shift;
317 29574 return $self->_inline_instance_get(@_) . ';';
318 }
319  
320 33582 ▶sub _inline_instance_get {
Subroutine _inline_instance_get: called CC=1 SCAR=0.0
321 33582 my $self = shift;
322 33582 my ($instance) = @_;
323  
324 33582 my $mi = $self->associated_class->get_meta_instance;
325 33581 return $mi->inline_get_slot_value($instance, $self->name);
326 }
327  
328 7436 ▶sub has_value {
Subroutine has_value: called CC=1 SCAR=0.0
Pod documented
329 7436 my $self = shift;
330 7436 my ($instance) = @_;
331  
332 7436 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
333 7436 return $mi->is_slot_initialized($instance, $self->name);
334 }
335  
336 6456 ▶sub _inline_has_value {
Subroutine _inline_has_value: called CC=1 SCAR=0.0
337 6456 my $self = shift;
338 6456 return $self->_inline_instance_has(@_) . ';';
339 }
340  
341 7209 ▶sub _inline_instance_has {
Subroutine _inline_instance_has: called CC=1 SCAR=0.0
342 7209 my $self = shift;
343 7209 my ($instance) = @_;
344  
345 7209 my $mi = $self->associated_class->get_meta_instance;
346 7208 return $mi->inline_is_slot_initialized($instance, $self->name);
347 }
348  
349 15 ▶sub clear_value {
Subroutine clear_value: called CC=1 SCAR=0.0
Pod documented
350 15 my $self = shift;
351 15 my ($instance) = @_;
352  
353 15 my $mi = Class::MOP::Class->initialize(ref($instance))->get_meta_instance;
354 15 return $mi->deinitialize_slot($instance, $self->name);
355 }
356  
357 80 ▶sub _inline_clear_value {
Subroutine _inline_clear_value: called CC=1 SCAR=0.0
358 80 my $self = shift;
359 80 return $self->_inline_instance_clear(@_) . ';';
360 }
361  
362 80 ▶sub _inline_instance_clear {
Subroutine _inline_instance_clear: called CC=1 SCAR=0.0
363 80 my $self = shift;
364 80 my ($instance) = @_;
365  
366 80 my $mi = $self->associated_class->get_meta_instance;
367 79 return $mi->inline_deinitialize_slot($instance, $self->name);
368 }
369  
370 ## load em up ...
371  
372 107147 ▶sub accessor_metaclass { 'Class::MOP::Method::Accessor' }
Subroutine accessor_metaclass: called CC=1 SCAR=0.0
Pod documented
373  
374 110392 ▶sub _process_accessors {
Subroutine _process_accessors: called CC=5 SCAR=16.1
375 110392 my ($self, $type, $accessor, $generate_as_inline_methods) = @_;
376  
377 110392 ▶ my $method_ctx = { %{ $self->definition_context || {} } };
Condition100%2/2
$self->definition_context || {}
l!l
110137255
MC/DC100%1/1
$self->definition_context || {}
$self->definition_context
Truth table100%2/2
A
A= $self->definition_context
Aresult
11
00
378  
379 110392 ▶ if (ref($accessor)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $accessor) { } 32137 78255 110392
380 32137 ▶ (ref($accessor) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
ref $accessor eq "HASH" or $self->_throw_exception("BadOptionFormat", "attribute", $self, "option_value", $accessor, "option_name", $type) 32135 2 32137
381 || $self->_throw_exception( BadOptionFormat => attribute => $self,
382 option_value => $accessor,
383 option_name => $type
384 );
385  
386 32135 my ($name, $method) = %{$accessor};
387  
388 32135 $method_ctx->{description} = $self->_accessor_description($name, $type);
389  
390 32135 $method = $self->accessor_metaclass->wrap(
391 $method,
392 attribute => $self,
393 package_name => $self->associated_class->name,
394 name => $name,
395 associated_metaclass => $self->associated_class,
396 definition_context => $method_ctx,
397 );
398 32135 $self->associate_method($method);
399 32135 return ($name, $method);
400 }
401 else {
402 78255 ▶ my $inline_me = ($generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable);
Condition66%2/3
$generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable
!ll&&!rl&&r
40820037435
MC/DC50%1/2
$generate_as_inline_methods && $self->associated_class->instance_metaclass->is_inlinable
$generate_as_inline_methods $self->associated_class->instance_metaclass->is_inlinable
Truth table66%2/3
A && B
A= $generate_as_inline_methodsB= $self->associated_class->instance_metaclass->is_inlinable
ABresult
0X0
100
111
403 78255 my $method;
404 78255 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
405 78255 $method_ctx->{description} = $self->_accessor_description($accessor, $type);
406  
407 78252 $method = $self->accessor_metaclass->new(
408 attribute => $self,
409 is_inline => $inline_me,
410 accessor_type => $type,
411 package_name => $self->associated_class->name,
412 name => $accessor,
413 associated_metaclass => $self->associated_class,
414 definition_context => $method_ctx,
415 );
416 }
417 3 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
418 3 $self->_throw_exception( CouldNotCreateMethod => attribute => $self,
419 option_value => $accessor,
420 option_name => $type,
421 error => $_
422 );
423 78255 };
424 78252 $self->associate_method($method);
425 78252 return ($accessor, $method);
426 }
427 }
428  
429 110390 ▶sub _accessor_description {
Subroutine _accessor_description: called CC=2 SCAR=6.9
430 110390 my $self = shift;
431 110390 my ($name, $type) = @_;
432  
433 110390 my $desc = "$type " . $self->associated_class->name . "::$name";
434 110387 ▶ if ( $name ne $self->name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name ne $self->name) 46563 63824 110387
435 46563 $desc .= " of attribute " . $self->name;
436 }
437  
438 110387 return $desc;
439 }
440  
441 87853 ▶sub install_accessors {
Subroutine install_accessors: called CC=6 SCAR=17.9
Pod documented
442 87853 my $self = shift;
443 87853 my $inline = shift;
444 87853 my $class = $self->associated_class;
445  
446 87853 ▶ $class->add_method(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_accessor 17368 70485 87853
447 $self->_process_accessors('accessor' => $self->accessor(), $inline)
448 ) if $self->has_accessor();
449  
450 87853 ▶ $class->add_method(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_reader 69413 18440 87853
451 $self->_process_accessors('reader' => $self->reader(), $inline)
452 ) if $self->has_reader();
453  
454 87851 ▶ $class->add_method(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_writer 3328 84523 87851
455 $self->_process_accessors('writer' => $self->writer(), $inline)
456 ) if $self->has_writer();
457  
458 87851 ▶ $class->add_method(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_predicate 19729 68122 87851
459 $self->_process_accessors('predicate' => $self->predicate(), $inline)
460 ) if $self->has_predicate();
461  
462 87849 ▶ $class->add_method(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_clearer 551 87298 87849
463 $self->_process_accessors('clearer' => $self->clearer(), $inline)
464 ) if $self->has_clearer();
465  
466 87849 return;
467 }
468  
469 {
470 59 ▶ my $_remove_accessor = sub {
Subroutine __ANON__: called CC=5 SCAR=18.4
471 59 my ($accessor, $class) = @_;
472 59 ▶ if (ref($accessor) && ref($accessor) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $accessor and ref $accessor eq "HASH") 0 59 59
Condition33%1/3
ref $accessor and ref $accessor eq "HASH"
!ll&&!rl&&r
5900
MC/DC0%0/2
ref $accessor and ref $accessor eq "HASH"
ref $accessor ref $accessor eq "HASH"
Truth table33%1/3
A and B
A= ref $accessorB= ref $accessor eq "HASH"
ABresult
0X0
100
111
473 0 ($accessor) = keys %{$accessor};
474 }
475 59 my $method = $class->get_method($accessor);
476 59 ▶ $class->remove_method($accessor)
Branch: 1 branch
BranchTrueFalseTotal
if ref $method and $method->isa("Class::MOP::Method::Accessor") 55 4 59
Condition66%2/3
ref $method and $method->isa("Class::MOP::Method::Accessor")
!ll&&!rl&&r
4055
MC/DC50%1/2
ref $method and $method->isa("Class::MOP::Method::Accessor")
ref $method $method->isa("Class::MOP::Method::Accessor")
Truth table66%2/3
A and B
A= ref $methodB= $method->isa("Class::MOP::Method::Accessor")
ABresult
0X0
100
111
477 if (ref($method) && $method->isa('Class::MOP::Method::Accessor'));
478 459 };
479  
480 68 ▶ sub remove_accessors {
Subroutine remove_accessors: called CC=6 SCAR=17.9
Pod documented
481 68 my $self = shift;
482 # TODO:
483 # we really need to make sure to remove from the
484 # associates methods here as well. But this is
485 # such a slimly used method, I am not worried
486 # about it right now.
487 68 ▶ $_remove_accessor->($self->accessor(), $self->associated_class()) if $self->has_accessor();
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_accessor 10 58 68
488 68 ▶ $_remove_accessor->($self->reader(), $self->associated_class()) if $self->has_reader();
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_reader 44 24 68
489 68 ▶ $_remove_accessor->($self->writer(), $self->associated_class()) if $self->has_writer();
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_writer 2 66 68
490 68 ▶ $_remove_accessor->($self->predicate(), $self->associated_class()) if $self->has_predicate();
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_predicate 2 66 68
491 68 ▶ $_remove_accessor->($self->clearer(), $self->associated_class()) if $self->has_clearer();
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_clearer 1 67 68
492 68 return;
493 }
494  
495 }
496  
497 459 1;
498  
499 # ABSTRACT: Attribute Meta Object
500  
501 __END__
« blib/lib/Moose/Meta/Class.pm ↑ Summary blib/lib/Moose/Meta/Role/Application/ToClass.pm »