« blib/lib/Moose/Meta/TypeConstraint/Class.pm
↑ Summary
blib/lib/Moose/Meta/TypeConstraint/Role.pm »
| 1 | package Class::MOP::MiniTrait; | ||||||||||
| 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 Module::Runtime 'use_package_optimistically'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 2653 | ▶ | sub apply { | ||||||||
|
Subroutine
apply: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 10 | 2653 | my ( $to_class, $trait ) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 2653 | for ( grep { !ref } $to_class, $trait ) { | |||||||||
| 13 | 4610 | use_package_optimistically($_); | |||||||||
| 14 | 4610 | $_ = Class::MOP::Class->initialize($_); | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 2653 | for my $meth ( grep { $_->package_name ne 'UNIVERSAL' } $trait->get_all_methods ) { | |||||||||
| 18 | 20159 | my $meth_name = $meth->name; | |||||||||
| 19 | 20159 | ▶ | next if index($meth_name, '__') == 0; # skip private subs | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 19463 | ▶ | if ( $to_class->find_method_by_name($meth_name) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 14721 | $to_class->add_around_method_modifier( $meth_name, $meth->body ); | |||||||||
| 23 | } | ||||||||||
| 24 | else { | ||||||||||
| 25 | 4742 | $to_class->add_method( $meth_name, $meth->clone ); | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | # We can't load this with use, since it may be loaded and used from Class::MOP | ||||||||||
| 31 | # (via Class::MOP::Class, etc). However, if for some reason this module is loaded | ||||||||||
| 32 | # _without_ first loading Class::MOP we need to require Class::MOP so we can | ||||||||||
| 33 | # use it and Class::MOP::Class. | ||||||||||
| 34 | 459 | require Class::MOP; | |||||||||
| 35 | |||||||||||
| 36 | 459 | 1; | |||||||||
| 37 | |||||||||||
| 38 | # ABSTRACT: Extremely limited trait application | ||||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||