| Filename | /home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/x86_64-linux/Moose/Meta/Role/Application/ToClass.pm |
| Statements | Executed 18 statements in 565µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 9µs | 10µs | Moose::Meta::Role::Application::ToClass::BEGIN@4 |
| 1 | 1 | 1 | 8µs | 28µs | Moose::Meta::Role::Application::ToClass::BEGIN@8 |
| 1 | 1 | 1 | 6µs | 19µs | Moose::Meta::Role::Application::ToClass::BEGIN@10 |
| 1 | 1 | 1 | 5µs | 82µs | Moose::Meta::Role::Application::ToClass::BEGIN@9 |
| 1 | 1 | 1 | 4µs | 7µs | Moose::Meta::Role::Application::ToClass::BEGIN@5 |
| 1 | 1 | 1 | 4µs | 282µs | Moose::Meta::Role::Application::ToClass::BEGIN@6 |
| 1 | 1 | 1 | 4µs | 16µs | Moose::Meta::Role::Application::ToClass::BEGIN@12 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::__ANON__[:95] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::apply |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::apply_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::apply_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::apply_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::apply_override_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::check_required_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::check_required_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToClass::check_role_exclusions |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Application::ToClass; | ||||
| 2 | 1 | 300ns | our $VERSION = '2.1605'; | ||
| 3 | |||||
| 4 | 2 | 14µs | 2 | 12µs | # spent 10µs (9+1) within Moose::Meta::Role::Application::ToClass::BEGIN@4 which was called:
# once (9µs+1µs) by Moose::BEGIN@36 at line 4 # spent 10µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@4
# spent 2µs making 1 call to strict::import |
| 5 | 2 | 13µs | 2 | 10µs | # spent 7µs (4+3) within Moose::Meta::Role::Application::ToClass::BEGIN@5 which was called:
# once (4µs+3µs) by Moose::BEGIN@36 at line 5 # spent 7µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@5
# spent 3µs making 1 call to warnings::import |
| 6 | 2 | 22µs | 2 | 559µs | # spent 282µs (4+278) within Moose::Meta::Role::Application::ToClass::BEGIN@6 which was called:
# once (4µs+278µs) by Moose::BEGIN@36 at line 6 # spent 282µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@6
# spent 278µs making 1 call to metaclass::import |
| 7 | |||||
| 8 | 2 | 19µs | 2 | 34µs | # spent 28µs (8+20) within Moose::Meta::Role::Application::ToClass::BEGIN@8 which was called:
# once (8µs+20µs) by Moose::BEGIN@36 at line 8 # spent 28µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@8
# spent 6µs making 1 call to List::Util::import |
| 9 | 2 | 20µs | 2 | 160µs | # spent 82µs (5+78) within Moose::Meta::Role::Application::ToClass::BEGIN@9 which was called:
# once (5µs+78µs) by Moose::BEGIN@36 at line 9 # spent 82µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@9
# spent 78µs making 1 call to Sub::Exporter::__ANON__[Sub/Exporter.pm:337] |
| 10 | 2 | 15µs | 2 | 33µs | # spent 19µs (6+14) within Moose::Meta::Role::Application::ToClass::BEGIN@10 which was called:
# once (6µs+14µs) by Moose::BEGIN@36 at line 10 # spent 19µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@10
# spent 14µs making 1 call to Exporter::import |
| 11 | |||||
| 12 | 2 | 455µs | 2 | 29µs | # spent 16µs (4+12) within Moose::Meta::Role::Application::ToClass::BEGIN@12 which was called:
# once (4µs+12µs) by Moose::BEGIN@36 at line 12 # spent 16µs making 1 call to Moose::Meta::Role::Application::ToClass::BEGIN@12
# spent 12µs making 1 call to parent::import |
| 13 | |||||
| 14 | 1 | 3µs | 3 | 207µs | __PACKAGE__->meta->add_attribute('role' => ( # spent 192µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 11µs making 1 call to Moose::Meta::Role::Application::ToClass::meta
# spent 4µs making 1 call to Class::MOP::_definition_context |
| 15 | reader => 'role', | ||||
| 16 | Class::MOP::_definition_context(), | ||||
| 17 | )); | ||||
| 18 | |||||
| 19 | 1 | 2µs | 3 | 178µs | __PACKAGE__->meta->add_attribute('class' => ( # spent 169µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 6µs making 1 call to Moose::Meta::Role::Application::ToClass::meta
# spent 3µs making 1 call to Class::MOP::_definition_context |
| 20 | accessor => 'class', | ||||
| 21 | Class::MOP::_definition_context(), | ||||
| 22 | )); | ||||
| 23 | |||||
| 24 | sub apply { | ||||
| 25 | my ($self, $role, $class) = @_; | ||||
| 26 | |||||
| 27 | # We need weak_ref in CMOP :( | ||||
| 28 | weaken($self->{role} = $role); | ||||
| 29 | weaken($self->{class} = $class); | ||||
| 30 | |||||
| 31 | $self->SUPER::apply($role, $class); | ||||
| 32 | |||||
| 33 | $class->add_role($role); | ||||
| 34 | $class->add_role_application($self); | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | sub check_role_exclusions { | ||||
| 38 | my ($self, $role, $class) = @_; | ||||
| 39 | if ($class->excludes_role($role->name)) { | ||||
| 40 | throw_exception( ConflictDetectedInCheckRoleExclusionsInToClass => class_name => $class->name, | ||||
| 41 | role_name => $role->name, | ||||
| 42 | ); | ||||
| 43 | } | ||||
| 44 | foreach my $excluded_role_name ($role->get_excluded_roles_list) { | ||||
| 45 | if ($class->does_role($excluded_role_name)) { | ||||
| 46 | throw_exception( ClassDoesTheExcludedRole => role_name => $role->name, | ||||
| 47 | excluded_role_name => $excluded_role_name, | ||||
| 48 | class_name => $class->name, | ||||
| 49 | ); | ||||
| 50 | } | ||||
| 51 | } | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | sub check_required_methods { | ||||
| 55 | my ($self, $role, $class) = @_; | ||||
| 56 | |||||
| 57 | my @missing; | ||||
| 58 | my @is_attr; | ||||
| 59 | |||||
| 60 | # NOTE: | ||||
| 61 | # we might need to move this down below the | ||||
| 62 | # the attributes so that we can require any | ||||
| 63 | # attribute accessors. However I am thinking | ||||
| 64 | # that maybe those are somehow exempt from | ||||
| 65 | # the require methods stuff. | ||||
| 66 | foreach my $required_method ($role->get_required_method_list) { | ||||
| 67 | my $required_method_name = $required_method->name; | ||||
| 68 | |||||
| 69 | if (!$class->find_method_by_name($required_method_name)) { | ||||
| 70 | |||||
| 71 | next if $self->is_aliased_method($required_method_name); | ||||
| 72 | |||||
| 73 | push @missing, $required_method; | ||||
| 74 | } | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | return unless @missing; | ||||
| 78 | |||||
| 79 | my $error = ''; | ||||
| 80 | |||||
| 81 | @missing = sort { $a->name cmp $b->name } @missing; | ||||
| 82 | my @conflicts = grep { $_->isa('Moose::Meta::Role::Method::Conflicting') } @missing; | ||||
| 83 | |||||
| 84 | if (@conflicts) { | ||||
| 85 | my $conflict = $conflicts[0]; | ||||
| 86 | my $roles = $conflict->roles_as_english_list; | ||||
| 87 | |||||
| 88 | my @same_role_conflicts = grep { $_->roles_as_english_list eq $roles } @conflicts; | ||||
| 89 | |||||
| 90 | throw_exception( MethodNameConflictInRoles => conflict => \@same_role_conflicts, | ||||
| 91 | class_name => $class->name | ||||
| 92 | ); | ||||
| 93 | } | ||||
| 94 | elsif (@missing) { | ||||
| 95 | if (my $meth = first { $class->name->can($_) } @missing) { | ||||
| 96 | throw_exception( RequiredMethodsImportedByClass => class_name => $class->name, | ||||
| 97 | role_name => $role->name, | ||||
| 98 | missing_methods => \@missing, | ||||
| 99 | imported_method => $meth | ||||
| 100 | ); | ||||
| 101 | } | ||||
| 102 | else { | ||||
| 103 | throw_exception( RequiredMethodsNotImplementedByClass => class_name => $class->name, | ||||
| 104 | role_name => $role->name, | ||||
| 105 | missing_methods => \@missing, | ||||
| 106 | ); | ||||
| 107 | } | ||||
| 108 | } | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | sub check_required_attributes { | ||||
| 112 | |||||
| 113 | } | ||||
| 114 | |||||
| 115 | sub apply_attributes { | ||||
| 116 | my ($self, $role, $class) = @_; | ||||
| 117 | |||||
| 118 | foreach my $attribute_name ($role->get_attribute_list) { | ||||
| 119 | # it if it has one already | ||||
| 120 | if ($class->has_attribute($attribute_name) && | ||||
| 121 | # make sure we haven't seen this one already too | ||||
| 122 | $class->get_attribute($attribute_name) != $role->get_attribute($attribute_name)) { | ||||
| 123 | next; | ||||
| 124 | } | ||||
| 125 | else { | ||||
| 126 | $class->add_attribute( | ||||
| 127 | $role->get_attribute($attribute_name)->attribute_for_class | ||||
| 128 | ); | ||||
| 129 | } | ||||
| 130 | } | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | sub apply_methods { | ||||
| 134 | my ( $self, $role, $class ) = @_; | ||||
| 135 | |||||
| 136 | foreach my $method ( $role->_get_local_methods ) { | ||||
| 137 | my $method_name = $method->name; | ||||
| 138 | |||||
| 139 | next if $method->isa('Class::MOP::Method::Meta'); | ||||
| 140 | |||||
| 141 | unless ( $self->is_method_excluded($method_name) ) { | ||||
| 142 | |||||
| 143 | my $class_method = $class->get_method($method_name); | ||||
| 144 | |||||
| 145 | next if $class_method && $class_method->body != $method->body; | ||||
| 146 | |||||
| 147 | $class->add_method( | ||||
| 148 | $method_name, | ||||
| 149 | $method, | ||||
| 150 | ); | ||||
| 151 | } | ||||
| 152 | |||||
| 153 | next unless $self->is_method_aliased($method_name); | ||||
| 154 | |||||
| 155 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | ||||
| 156 | |||||
| 157 | my $class_method = $class->get_method($aliased_method_name); | ||||
| 158 | |||||
| 159 | if ( $class_method && $class_method->body != $method->body ) { | ||||
| 160 | throw_exception( CannotCreateMethodAliasLocalMethodIsPresentInClass => aliased_method_name => $aliased_method_name, | ||||
| 161 | method => $method, | ||||
| 162 | role_name => $role->name, | ||||
| 163 | class_name => $class->name, | ||||
| 164 | ); | ||||
| 165 | } | ||||
| 166 | |||||
| 167 | $class->add_method( | ||||
| 168 | $aliased_method_name, | ||||
| 169 | $method, | ||||
| 170 | ); | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | # we must reset the cache here since | ||||
| 174 | # we are just aliasing methods, otherwise | ||||
| 175 | # the modifiers go wonky. | ||||
| 176 | $class->reset_package_cache_flag; | ||||
| 177 | } | ||||
| 178 | |||||
| 179 | sub apply_override_method_modifiers { | ||||
| 180 | my ($self, $role, $class) = @_; | ||||
| 181 | foreach my $method_name ($role->get_method_modifier_list('override')) { | ||||
| 182 | # it if it has one already then ... | ||||
| 183 | if ($class->has_method($method_name)) { | ||||
| 184 | next; | ||||
| 185 | } | ||||
| 186 | else { | ||||
| 187 | # if this is not a role, then we need to | ||||
| 188 | # find the original package of the method | ||||
| 189 | # so that we can tell the class were to | ||||
| 190 | # find the right super() method | ||||
| 191 | my $method = $role->get_override_method_modifier($method_name); | ||||
| 192 | my ($package) = Class::MOP::get_code_info($method); | ||||
| 193 | # if it is a class, we just add it | ||||
| 194 | $class->add_override_method_modifier($method_name, $method, $package); | ||||
| 195 | } | ||||
| 196 | } | ||||
| 197 | } | ||||
| 198 | |||||
| 199 | sub apply_method_modifiers { | ||||
| 200 | my ($self, $modifier_type, $role, $class) = @_; | ||||
| 201 | my $add = "add_${modifier_type}_method_modifier"; | ||||
| 202 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
| 203 | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { | ||||
| 204 | $class->$add( | ||||
| 205 | $method_name, | ||||
| 206 | $_ | ||||
| 207 | ) foreach $role->$get($method_name); | ||||
| 208 | } | ||||
| 209 | } | ||||
| 210 | |||||
| 211 | 1 | 4µs | 1; | ||
| 212 | |||||
| 213 | # ABSTRACT: Compose a role into a class | ||||
| 214 | |||||
| 215 | __END__ |