blib/lib/Mouse/Meta/Class.pm

filter: Statementstmt 98.8% 258 / 261 Branchbran 90.6% 87 / 96 Conditioncond 70.0% 14 / 20 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 100% 34 / 34 Podpod 15.0% 3 / 20 totaltotal 90.2% 400 / 443 CC 136 SCAR 19.3
CC
136
Cov
95%
add_attribute
13.0
__ANON__
9.0
blau
9.0
CRAP 6.9
« blib/lib/Mouse/Util/TypeConstraints.pm ↑ Summary blib/lib/Mouse/Meta/Method.pm »
1 package Mouse::Meta::Class;
2 285 ▶use Mouse::Util qw/:meta/; # enables strict and warnings
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 285 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 285 ▶use Mouse::Meta::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 285 our @ISA = qw(Mouse::Meta::Module);
8  
9 285 our @CARP_NOT = qw(Mouse); # trust Mouse
10  
11 sub attribute_metaclass;
12 sub method_metaclass;
13  
14 sub constructor_class;
15 sub destructor_class;
16  
17  
18 758 ▶sub _construct_meta {
Subroutine _construct_meta: called CC=3 SCAR=11.0
19 758 my($class, %args) = @_;
20  
21 758 $args{attributes} = {};
22 758 $args{methods} = {};
23 758 $args{roles} = [];
24  
25 758 $args{superclasses} = do {
26 285 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 758 \@{ $args{package} . '::ISA' };
28 };
29  
30 758 ▶ my $self = bless \%args, ref($class) || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
247340
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
31 758 ▶ if(ref($self) ne __PACKAGE__){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne __PACKAGE__) 26 732 758
32 26 $self->meta->_initialize_object($self, \%args);
33 }
34 758 return $self;
35 }
36  
37 99 ▶sub create_anon_class{
Subroutine create_anon_class: called CC=1 SCAR=0.0
Pod undocumented
38 99 my $self = shift;
39 99 return $self->create(undef, @_);
40 }
41  
42 sub is_anon_class;
43  
44 sub roles;
45  
46 10 ▶sub calculate_all_roles {
Subroutine calculate_all_roles: called CC=1 SCAR=0.0
Pod undocumented
47 10 my $self = shift;
48 10 my %seen;
49 12 return grep { !$seen{ $_->name }++ }
50 10 map { $_->calculate_all_roles } @{ $self->roles };
51 }
52  
53 1330 ▶sub superclasses {
Subroutine superclasses: called CC=4 SCAR=13.9
Pod documented
54 1330 my $self = shift;
55  
56 1330 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 751 579 1330
57 751 foreach my $super(@_){
58 757 Mouse::Util::load_class($super);
59 755 my $meta = Mouse::Util::get_metaclass_by_name($super);
60 755 ▶ next if $self->verify_superclass($super, $meta);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verify_superclass($super, $meta) 750 4 754
61 4 $self->_reconcile_with_superclass_meta($meta);
62 }
63 748 return @{ $self->{superclasses} } = @_;
64 }
65  
66 579 return @{ $self->{superclasses} };
67 }
68  
69 755 ▶sub verify_superclass {
Subroutine verify_superclass: called CC=7 SCAR=19.5
Pod undocumented
70 755 my($self, $super, $super_meta) = @_;
71  
72 755 ▶ if(defined $super_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $super_meta) { } 163 592 755
73 163 ▶ if(Mouse::Util::is_a_metarole($super_meta)){
Branch: 1 branch
BranchTrueFalseTotal
if (Mouse::Util::is_a_metarole($super_meta)) 1 162 163
74 1 $self->throw_error("You cannot inherit from a Mouse Role ($super)");
75 }
76 }
77 else {
78 # The metaclass of $super is not initialized.
79 # i.e. it might be Mouse::Object, a mixin package (e.g. Exporter),
80 # or a foreign class including Moose classes.
81 # See also Mouse::Foreign::Meta::Role::Class.
82 592 my $mm = $super->can('meta');
83 592 ▶ if(!($mm && $mm == \&Mouse::Util::meta)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mm and $mm == \&Mouse::Util::meta) 5 587 592
Condition66%2/3
$mm and $mm == \&Mouse::Util::meta
!ll&&!rl&&r
50587
MC/DC50%1/2
$mm and $mm == \&Mouse::Util::meta
$mm $mm == \&Mouse::Util::meta
Truth table66%2/3
A and B
A= $mmB= $mm == \&Mouse::Util::meta
ABresult
0X0
100
111
84 5 ▶ if($super->can('new') or $super->can('DESTROY')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($super->can("new") or $super->can("DESTROY")) 2 3 5
Condition66%2/3
$super->can("new") or $super->can("DESTROY")
l!l&&r!l&&!r
203
MC/DC50%1/2
$super->can("new") or $super->can("DESTROY")
$super->can("new") $super->can("DESTROY")
Truth table66%2/3
A or B
A= $super->can("new")B= $super->can("DESTROY")
ABresult
1X1
011
000
85 2 $self->inherit_from_foreign_class($super);
86 }
87 }
88 592 return 1; # always ok
89 }
90  
91 162 return $self->isa(ref $super_meta); # checks metaclass compatibility
92 }
93  
94 2 ▶sub inherit_from_foreign_class {
Subroutine inherit_from_foreign_class: called CC=2 SCAR=7.6
Pod undocumented
95 2 my($class, $super) = @_;
96 2 ▶ if($ENV{PERL_MOUSE_STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"PERL_MOUSE_STRICT"}) 0 2 2
97 0 Carp::carp("You inherit from non-Mouse class ($super),"
98 . " but it is unlikely to work correctly."
99 . " Please consider using MouseX::Foreign");
100 }
101 2 return;
102 }
103  
104 285 my @MetaClassTypes = (
105 'attribute', # Mouse::Meta::Attribute
106 'method', # Mouse::Meta::Method
107 'constructor', # Mouse::Meta::Method::Constructor
108 'destructor', # Mouse::Meta::Method::Destructor
109 );
110  
111 4 ▶sub _reconcile_with_superclass_meta {
Subroutine _reconcile_with_superclass_meta: called CC=4 SCAR=13.9
112 4 my($self, $other) = @_;
113  
114 # find incompatible traits
115 4 my %metaroles;
116 4 foreach my $metaclass_type(@MetaClassTypes){
117 16 ▶ my $accessor = $self->can($metaclass_type . '_metaclass')
Condition66%2/3
$self->can($metaclass_type . '_metaclass') || $self->can($metaclass_type . '_class')
l!l&&r!l&&!r
880
MC/DC0%0/2
$self->can($metaclass_type . '_metaclass') || $self->can($metaclass_type . '_class')
$self->can($metaclass_type . '_metaclass') $self->can($metaclass_type . '_class')
Truth table66%2/3
A || B
A= $self->can($metaclass_type . '_metaclass')B= $self->can($metaclass_type . '_class')
ABresult
1X1
011
000
118 || $self->can($metaclass_type . '_class');
119  
120 16 my $other_c = $other->$accessor();
121 16 my $self_c = $self->$accessor();
122  
123 16 ▶ if(!$self_c->isa($other_c)){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self_c->isa($other_c)) 1 15 16
124 1 $metaroles{$metaclass_type}
125 = [ $self_c->meta->_collect_roles($other_c->meta) ];
126 }
127 }
128  
129 4 $metaroles{class} = [$self->meta->_collect_roles($other->meta)];
130  
131 #use Data::Dumper; print Data::Dumper->new([\%metaroles], ['*metaroles'])->Indent(1)->Dump;
132  
133 4 require Mouse::Util::MetaRole;
134 4 $_[0] = Mouse::Util::MetaRole::apply_metaroles(
135 for => $self,
136 class_metaroles => \%metaroles,
137 );
138 4 return;
139 }
140  
141 5 ▶sub _collect_roles {
Subroutine _collect_roles: called CC=5 SCAR=16.3
142 5 my ($self, $other) = @_;
143  
144 # find common ancestor
145 5 my @self_lin_isa = $self->linearized_isa;
146 5 my @other_lin_isa = $other->linearized_isa;
147  
148 5 my(@self_anon_supers, @other_anon_supers);
149 5 ▶ push @self_anon_supers, shift @self_lin_isa while $self_lin_isa[0]->meta->is_anon_class;
Branch: 1 branch
BranchTrueFalseTotal
$self_lin_isa[0]->meta->is_anon_class and do { push @self_anon_supers, shift @self_lin_isa } 4 5 9
150 5 ▶ push @other_anon_supers, shift @other_lin_isa while $other_lin_isa[0]->meta->is_anon_class;
Branch: 1 branch
BranchTrueFalseTotal
$other_lin_isa[0]->meta->is_anon_class and do { push @other_anon_supers, shift @other_lin_isa } 6 5 11
151  
152 5 ▶ my $common_ancestor = $self_lin_isa[0] eq $other_lin_isa[0] && $self_lin_isa[0];
Condition33%1/3
$self_lin_isa[0] eq $other_lin_isa[0] && $self_lin_isa[0]
!ll&&!rl&&r
005
MC/DC0%0/2
$self_lin_isa[0] eq $other_lin_isa[0] && $self_lin_isa[0]
$self_lin_isa[0] eq $other_lin_isa[0] $self_lin_isa[0]
Truth table33%1/3
A && B
A= $self_lin_isa[0] eq $other_lin_isa[0]B= $self_lin_isa[0]
ABresult
0X0
100
111
153  
154 5 ▶ if(!$common_ancestor){
Branch: 1 branch
BranchTrueFalseTotal
unless ($common_ancestor) 0 5 5
155 0 $self->throw_error(sprintf '%s cannot have %s as a super class because of their metaclass incompatibility',
156 $self->name, $other->name);
157 }
158  
159 5 my %seen;
160 12 return sort grep { !$seen{$_}++ } ## no critic
161 4 (map{ $_->name } map{ $_->meta->calculate_all_roles } @self_anon_supers),
162 5 (map{ $_->name } map{ $_->meta->calculate_all_roles } @other_anon_supers),
163 ;
164 }
165  
166  
167 21 ▶sub find_method_by_name {
Subroutine find_method_by_name: called CC=4 SCAR=14.2
Pod undocumented
168 21 my($self, $method_name) = @_;
169 21 ▶ defined($method_name)
Branch: 1 branch
BranchTrueFalseTotal
defined $method_name or $self->throw_error("You must define a method name to find") 21 0 21
170 or $self->throw_error('You must define a method name to find');
171  
172 21 foreach my $class( $self->linearized_isa ){
173 39 my $method = $self->initialize($class)->get_method($method_name);
174 39 ▶ return $method if defined $method;
Branch: 1 branch
BranchTrueFalseTotal
if defined $method 21 18 39
175 }
176 0 return undef;
177 }
178  
179 1 ▶sub get_all_methods {
Subroutine get_all_methods: called CC=1 SCAR=0.0
Pod documented
180 1 my($self) = @_;
181 1 return map{ $self->find_method_by_name($_) } $self->get_all_method_names;
182 }
183  
184 9 ▶sub get_all_method_names {
Subroutine get_all_method_names: called CC=1 SCAR=0.0
Pod undocumented
185 9 my $self = shift;
186 9 my %uniq;
187 77 return grep { $uniq{$_}++ == 0 }
188 9 map { Mouse::Meta::Class->initialize($_)->get_method_list() }
189 $self->linearized_isa;
190 }
191  
192 14 ▶sub find_attribute_by_name {
Subroutine find_attribute_by_name: called CC=4 SCAR=13.9
Pod undocumented
193 14 my($self, $name) = @_;
194 14 ▶ defined($name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $self->throw_error("You must define an attribute name to find") 14 0 14
195 or $self->throw_error('You must define an attribute name to find');
196 14 foreach my $attr($self->get_all_attributes) {
197 22 ▶ return $attr if $attr->name eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $attr->name eq $name 13 9 22
198 }
199 1 return undef;
200 }
201  
202 605 ▶sub add_attribute {
Subroutine add_attribute: called CC=13 SCAR=25.7
Pod documented
203 605 my $self = shift;
204  
205 605 my($attr, $name);
206  
207 605 ▶ if(Scalar::Util::blessed($_[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 4 601 605
208 4 $attr = $_[0];
209  
210 4 ▶ $attr->isa('Mouse::Meta::Attribute')
Branch: 1 branch
BranchTrueFalseTotal
$attr->isa("Mouse::Meta::Attribute") or $self->throw_error("Your attribute must be an instance of Mouse::Meta::Attribute (or a subclass)") 4 0 4
211 || $self->throw_error("Your attribute must be an instance of Mouse::Meta::Attribute (or a subclass)");
212  
213 4 $name = $attr->name;
214 }
215 else{
216 # _process_attribute
217 601 $name = shift;
218  
219 601 ▶ my %args = (@_ == 1) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 84 517 601
220  
221 601 ▶ defined($name)
Branch: 1 branch
BranchTrueFalseTotal
defined $name or $self->throw_error("You must provide a name for the attribute") 601 0 601
222 or $self->throw_error('You must provide a name for the attribute');
223  
224 601 ▶ if ($name =~ s/^\+//) { # inherited attributes
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ s/^\+//) { } 35 566 601
225 # Workaround for https://github.com/gfx/p5-Mouse/issues/64
226 # Do not use find_attribute_by_name to avoid problems with cached attributes list
227 # because we're about to change it anyway
228 35 my $inherited_attr;
229 35 foreach my $i ( @{ $self->_calculate_all_attributes } ) {
230 81 ▶ if ( $i->name eq $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i->name eq $name) 33 48 81
231 33 $inherited_attr = $i;
232 33 last;
233 }
234 }
235 35 ▶ $self->throw_error("Could not find an attribute by the name of '$name' to inherit from in ".$self->name)
Branch: 1 branch
BranchTrueFalseTotal
unless $inherited_attr 2 33 35
236 unless $inherited_attr;
237  
238 33 $attr = $inherited_attr->clone_and_inherit_options(%args);
239 }
240 else{
241 566 my($attribute_class, @traits) = $self->attribute_metaclass->interpolate_class(\%args);
242 566 ▶ $args{traits} = \@traits if @traits;
Branch: 1 branch
BranchTrueFalseTotal
if @traits 9 557 566
243  
244 566 $attr = $attribute_class->new($name, %args);
245 }
246 }
247  
248 587 Scalar::Util::weaken( $attr->{associated_class} = $self );
249  
250 # install accessors first
251 587 $attr->install_accessors();
252  
253 # then register the attribute to the metaclass
254 583 $attr->{insertion_order} = keys %{ $self->{attributes} };
255 583 $self->{attributes}{$name} = $attr;
256 583 $self->_invalidate_metaclass_cache();
257  
258 583 ▶ if(!$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){
Branch: 1 branch
BranchTrueFalseTotal
if (not $attr->{"associated_methods"} and ($attr->{"is"} || "") ne "bare") 2 581 583
Condition100%5/5
not $attr->{"associated_methods"} and ($attr->{"is"} || "") ne "bare"
!ll&&!rl&&r
543382
$attr->{'is'} || ''
l!l
382
MC/DC100%2/2
not $attr->{"associated_methods"} and ($attr->{"is"} || "") ne "bare"
not $attr->{"associated_methods"} $attr->{'is'}
Truth table100%3/3
not(A) and B
A= not $attr->{"associated_methods"}B= $attr->{'is'}
ABresult
0X0
100
111
259 2 Carp::carp(qq{Attribute ($name) of class }.$self->name
260 .qq{ has no associated methods (did you mean to provide an "is" argument?)});
261 }
262 583 return $attr;
263 }
264  
265 539 ▶sub _calculate_all_attributes {
Subroutine _calculate_all_attributes: called CC=3 SCAR=11.0
266 539 my($self) = @_;
267 539 my %seen;
268 my @all_attrs;
269 539 foreach my $class($self->linearized_isa) {
270 1267 ▶ my $meta = Mouse::Util::get_metaclass_by_name($class) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $meta = Mouse::Util::get_metaclass_by_name($class) or next 716 551 1267
271 716 my @attrs = grep { !$seen{$_->name}++ } values %{$meta->{attributes}};
272 @attrs = sort {
273 716 $b->{insertion_order} <=> $a->{insertion_order}
274 870 } @attrs;
275 716 push @all_attrs, @attrs;
276 }
277 539 return [reverse @all_attrs];
278 }
279  
280 sub linearized_isa;
281  
282 sub new_object;
283 sub clone_object;
284  
285 84 ▶sub immutable_options {
Subroutine immutable_options: called CC=1 SCAR=0.0
Pod undocumented
286 84 my ( $self, @args ) = @_;
287  
288 return (
289 84 inline_constructor => 1,
290 inline_destructor => 1,
291 constructor_name => 'new',
292 @args,
293 );
294 }
295  
296 84 ▶sub make_immutable {
Subroutine make_immutable: called CC=3 SCAR=11.1
Pod undocumented
297 84 my $self = shift;
298 84 my %args = $self->immutable_options(@_);
299  
300 84 $self->{is_immutable}++;
301  
302 84 ▶ if ($args{inline_constructor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"inline_constructor"}) 84 0 84
303 $self->add_method($args{constructor_name} =>
304 84 Mouse::Util::load_class($self->constructor_class)
305 ->_generate_constructor($self, \%args));
306 }
307  
308 84 ▶ if ($args{inline_destructor}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"inline_destructor"}) 84 0 84
309 84 $self->add_method(DESTROY =>
310 Mouse::Util::load_class($self->destructor_class)
311 ->_generate_destructor($self, \%args));
312 }
313  
314 # Moose's make_immutable returns true allowing calling code to skip
315 # setting an explicit true value at the end of a source file.
316 84 return 1;
317 }
318  
319 2 ▶sub make_mutable {
Subroutine make_mutable: called CC=1 SCAR=0.0
Pod undocumented
320 2 my($self) = @_;
321 2 $self->{is_immutable} = 0;
322 2 return;
323 }
324  
325 sub is_immutable;
326 10 ▶sub is_mutable { !$_[0]->is_immutable }
Subroutine is_mutable: called CC=1 SCAR=0.0
Pod undocumented
327  
328 79 ▶sub _install_modifier {
Subroutine _install_modifier: called CC=5 SCAR=16.1
329 79 my( $self, $type, $name, $code ) = @_;
330 79 my $into = $self->name;
331  
332 79 ▶ my $original = $into->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $original = $into->can($name) or $self->throw_error("The method '${name}' was not found in the inheritance hierarchy for $into") 78 1 79
333 or $self->throw_error("The method '$name' was not found in the inheritance hierarchy for $into");
334  
335 78 my $modifier_table = $self->{modifiers}{$name};
336  
337 78 ▶ if(!$modifier_table){
Branch: 1 branch
BranchTrueFalseTotal
unless ($modifier_table) 56 22 78
338 56 my(@before, @after, @around);
339 56 my $cache = $original;
340 39 ▶ my $modified = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
341 39 ▶ if(@before) {
Branch: 2 branches
BranchTrueFalseTotal
if (@before) 17 22 39
if (@before) 7 33 40
342 17 for my $c (@before) { $c->(@_) }
343 }
344 39 ▶ unless(@after) {
Branch: 2 branches
BranchTrueFalseTotal
unless (@after) 22 17 39
unless (@after) 29 11 40
345 22 return $cache->(@_);
346 }
347  
348 17 ▶ if(wantarray){ # list context
Branch: 4 branches
BranchTrueFalseTotal
if (wantarray) { } 1 16 17
elsif (defined wantarray) { } 2 14 16
if (wantarray) { } 1 10 11
elsif (defined wantarray) { } 1 9 10
349 1 my @rval = $cache->(@_);
350  
351 1 for my $c(@after){ $c->(@_) }
352 1 return @rval;
353 }
354 elsif(defined wantarray){ # scalar context
355 2 my $rval = $cache->(@_);
356  
357 2 for my $c(@after){ $c->(@_) }
358 2 return $rval;
359 }
360 else{ # void context
361 14 $cache->(@_);
362  
363 14 for my $c(@after){ $c->(@_) }
364 14 return;
365 }
366 56 };
367  
368 56 $self->{modifiers}{$name} = $modifier_table = {
369 original => $original,
370  
371 before => \@before,
372 after => \@after,
373 around => \@around,
374  
375 cache => \$cache, # cache for around modifiers
376 };
377  
378 56 $self->add_method($name => $modified);
379 }
380  
381 78 ▶ if($type eq 'before'){
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'before') { } 23 55 78
elsif ($type eq 'after') { } 24 31 55
382 23 unshift @{$modifier_table->{before}}, $code;
383 }
384 elsif($type eq 'after'){
385 24 push @{$modifier_table->{after}}, $code;
386 }
387 else{ # around
388 31 push @{$modifier_table->{around}}, $code;
389  
390 31 my $next = ${ $modifier_table->{cache} };
391 31 ▶ ${ $modifier_table->{cache} } = sub{ $code->($next, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
392 }
393  
394 78 return;
395 }
396  
397 23 ▶sub add_before_method_modifier {
Subroutine add_before_method_modifier: called CC=1 SCAR=0.0
Pod undocumented
398 23 my ( $self, $name, $code ) = @_;
399 23 $self->_install_modifier( 'before', $name, $code );
400 }
401  
402 32 ▶sub add_around_method_modifier {
Subroutine add_around_method_modifier: called CC=1 SCAR=0.0
Pod undocumented
403 32 my ( $self, $name, $code ) = @_;
404 32 $self->_install_modifier( 'around', $name, $code );
405 }
406  
407 24 ▶sub add_after_method_modifier {
Subroutine add_after_method_modifier: called CC=1 SCAR=0.0
Pod undocumented
408 24 my ( $self, $name, $code ) = @_;
409 24 $self->_install_modifier( 'after', $name, $code );
410 }
411  
412 24 ▶sub add_override_method_modifier {
Subroutine add_override_method_modifier: called CC=3 SCAR=11.0
Pod undocumented
413 24 my ($self, $name, $code) = @_;
414  
415 24 ▶ if($self->has_method($name)){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_method($name)) 1 23 24
416 1 $self->throw_error("Cannot add an override method if a local method is already present");
417 }
418  
419 23 my $package = $self->name;
420  
421 23 ▶ my $super_body = $package->can($name)
Branch: 1 branch
BranchTrueFalseTotal
my $super_body = $package->can($name) or $self->throw_error("You cannot override '${name}' because it has no super method") 21 2 23
422 or $self->throw_error("You cannot override '$name' because it has no super method");
423  
424 14 ▶ $self->add_method($name => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
425 14 local $Mouse::SUPER_PACKAGE = $package;
426 14 local $Mouse::SUPER_BODY = $super_body;
427 14 local @Mouse::SUPER_ARGS = @_;
428 14 &{$code};
429 21 });
430 21 return;
431 }
432  
433 11 ▶sub add_augment_method_modifier {
Subroutine add_augment_method_modifier: called CC=3 SCAR=11.0
Pod undocumented
434 11 my ($self, $name, $code) = @_;
435 11 ▶ if($self->has_method($name)){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_method($name)) 1 10 11
436 1 $self->throw_error("Cannot add an augment method if a local method is already present");
437 }
438  
439 10 ▶ my $super = $self->find_method_by_name($name)
Branch: 1 branch
BranchTrueFalseTotal
my $super = $self->find_method_by_name($name) or $self->throw_error("You cannot augment '${name}' because it has no super method") 10 0 10
440 or $self->throw_error("You cannot augment '$name' because it has no super method");
441  
442 10 my $super_package = $super->package_name;
443 10 my $super_body = $super->body;
444  
445 3 ▶ $self->add_method($name => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine create: called CC=1 SCAR=0.0
446 3 local $Mouse::INNER_BODY{$super_package} = $code;
447 3 local $Mouse::INNER_ARGS{$super_package} = [@_];
448 3 &{$super_body};
449 10 });
450 10 return;
451 }
452  
453 510 ▶sub does_role {
Subroutine does_role: called CC=7 SCAR=19.5
Pod undocumented
454 510 my ($self, $role_name) = @_;
455  
456 510 ▶ (defined $role_name)
Branch: 1 branch
BranchTrueFalseTotal
defined $role_name or $self->throw_error("You must supply a role name to look for") 509 1 510
457 || $self->throw_error("You must supply a role name to look for");
458  
459 509 ▶ $role_name = $role_name->name if ref $role_name;
Branch: 1 branch
BranchTrueFalseTotal
if ref $role_name 278 231 509
460  
461 509 for my $class ($self->linearized_isa) {
462 865 ▶ my $meta = Mouse::Util::get_metaclass_by_name($class)
Branch: 1 branch
BranchTrueFalseTotal
my $meta = Mouse::Util::get_metaclass_by_name($class) or next 624 241 865
463 or next;
464  
465 624 for my $role (@{ $meta->roles }) {
466  
467 311 ▶ return 1 if $role->does_role($role_name);
Branch: 1 branch
BranchTrueFalseTotal
if $role->does_role($role_name) 241 70 311
468 }
469 }
470  
471 268 return 0;
472 }
473  
474 285 1;
475 __END__
« blib/lib/Mouse/Util/TypeConstraints.pm ↑ Summary blib/lib/Mouse/Meta/Method.pm »