| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Role/Application/ToRole.pm |
| Statements | Executed 19 statements in 791µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 10µs | 10µs | Moose::Meta::Role::Application::ToRole::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 581µs | Moose::Meta::Role::Application::ToRole::BEGIN@11 |
| 1 | 1 | 1 | 9µs | 51µs | Moose::Meta::Role::Application::ToRole::BEGIN@13 |
| 1 | 1 | 1 | 9µs | 25µs | Moose::Meta::Role::Application::ToRole::BEGIN@10 |
| 1 | 1 | 1 | 8µs | 13µs | Moose::Meta::Role::Application::ToRole::BEGIN@9 |
| 1 | 1 | 1 | 8µs | 84µs | Moose::Meta::Role::Application::ToRole::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::apply |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::apply_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::apply_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::apply_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::apply_override_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::check_required_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::check_required_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::ToRole::check_role_exclusions |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Application::ToRole; | ||||
| 2 | # spent 10µs within Moose::Meta::Role::Application::ToRole::BEGIN@2 which was called:
# once (10µs+0s) by Moose::BEGIN@41 at line 4 | ||||
| 3 | 1 | 5µs | $Moose::Meta::Role::Application::ToRole::AUTHORITY = 'cpan:STEVAN'; | ||
| 4 | 1 | 24µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@2 |
| 5 | { | ||||
| 6 | 2 | 1µs | $Moose::Meta::Role::Application::ToRole::VERSION = '2.0602'; | ||
| 7 | } | ||||
| 8 | |||||
| 9 | 3 | 19µs | 2 | 18µs | # spent 13µs (8+5) within Moose::Meta::Role::Application::ToRole::BEGIN@9 which was called:
# once (8µs+5µs) by Moose::BEGIN@41 at line 9 # spent 13µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@9
# spent 5µs making 1 call to strict::import |
| 10 | 3 | 42µs | 2 | 40µs | # spent 25µs (9+16) within Moose::Meta::Role::Application::ToRole::BEGIN@10 which was called:
# once (9µs+16µs) by Moose::BEGIN@41 at line 10 # spent 25µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@10
# spent 16µs making 1 call to warnings::import |
| 11 | 3 | 33µs | 2 | 1.15ms | # spent 581µs (9+571) within Moose::Meta::Role::Application::ToRole::BEGIN@11 which was called:
# once (9µs+571µs) by Moose::BEGIN@41 at line 11 # spent 581µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@11
# spent 571µs making 1 call to metaclass::import |
| 12 | |||||
| 13 | 3 | 28µs | 2 | 92µs | # spent 51µs (9+42) within Moose::Meta::Role::Application::ToRole::BEGIN@13 which was called:
# once (9µs+42µs) by Moose::BEGIN@41 at line 13 # spent 51µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@13
# spent 42µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 3 | 635µs | 2 | 160µs | # spent 84µs (8+76) within Moose::Meta::Role::Application::ToRole::BEGIN@15 which was called:
# once (8µs+76µs) by Moose::BEGIN@41 at line 15 # spent 84µs making 1 call to Moose::Meta::Role::Application::ToRole::BEGIN@15
# spent 76µs making 1 call to base::import |
| 16 | |||||
| 17 | sub apply { | ||||
| 18 | my ($self, $role1, $role2) = @_; | ||||
| 19 | $self->SUPER::apply($role1, $role2); | ||||
| 20 | $role2->add_role($role1); | ||||
| 21 | } | ||||
| 22 | |||||
| 23 | sub check_role_exclusions { | ||||
| 24 | my ($self, $role1, $role2) = @_; | ||||
| 25 | if ( $role2->excludes_role($role1->name) ) { | ||||
| 26 | require Moose; | ||||
| 27 | Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'"); | ||||
| 28 | } | ||||
| 29 | foreach my $excluded_role_name ($role1->get_excluded_roles_list) { | ||||
| 30 | if ( $role2->does_role($excluded_role_name) ) { | ||||
| 31 | require Moose; | ||||
| 32 | Moose->throw_error("The role " . $role2->name . " does the excluded role '$excluded_role_name'"); | ||||
| 33 | } | ||||
| 34 | $role2->add_excluded_roles($excluded_role_name); | ||||
| 35 | } | ||||
| 36 | } | ||||
| 37 | |||||
| 38 | sub check_required_methods { | ||||
| 39 | my ($self, $role1, $role2) = @_; | ||||
| 40 | foreach my $required_method ($role1->get_required_method_list) { | ||||
| 41 | my $required_method_name = $required_method->name; | ||||
| 42 | |||||
| 43 | next if $self->is_aliased_method($required_method_name); | ||||
| 44 | |||||
| 45 | $role2->add_required_methods($required_method) | ||||
| 46 | unless $role2->find_method_by_name($required_method_name); | ||||
| 47 | } | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | sub check_required_attributes { | ||||
| 51 | |||||
| 52 | } | ||||
| 53 | |||||
| 54 | sub apply_attributes { | ||||
| 55 | my ($self, $role1, $role2) = @_; | ||||
| 56 | foreach my $attribute_name ($role1->get_attribute_list) { | ||||
| 57 | # it if it has one already | ||||
| 58 | if ($role2->has_attribute($attribute_name) && | ||||
| 59 | # make sure we haven't seen this one already too | ||||
| 60 | $role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) { | ||||
| 61 | |||||
| 62 | my $role2_name = $role2->name; | ||||
| 63 | |||||
| 64 | require Moose; | ||||
| 65 | Moose->throw_error( "Role '" | ||||
| 66 | . $role1->name | ||||
| 67 | . "' has encountered an attribute conflict" | ||||
| 68 | . " while being composed into '$role2_name'." | ||||
| 69 | . " This is a fatal error and cannot be disambiguated." | ||||
| 70 | . " The conflicting attribute is named '$attribute_name'." ); | ||||
| 71 | } | ||||
| 72 | else { | ||||
| 73 | $role2->add_attribute( | ||||
| 74 | $role1->get_attribute($attribute_name)->clone | ||||
| 75 | ); | ||||
| 76 | } | ||||
| 77 | } | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | sub apply_methods { | ||||
| 81 | my ( $self, $role1, $role2 ) = @_; | ||||
| 82 | foreach my $method ( $role1->_get_local_methods ) { | ||||
| 83 | |||||
| 84 | my $method_name = $method->name; | ||||
| 85 | |||||
| 86 | next if $method->isa('Class::MOP::Method::Meta'); | ||||
| 87 | |||||
| 88 | unless ( $self->is_method_excluded($method_name) ) { | ||||
| 89 | |||||
| 90 | my $role2_method = $role2->get_method($method_name); | ||||
| 91 | if ( $role2_method | ||||
| 92 | && $role2_method->body != $method->body ) { | ||||
| 93 | |||||
| 94 | # method conflicts between roles result in the method becoming | ||||
| 95 | # a requirement | ||||
| 96 | $role2->add_conflicting_method( | ||||
| 97 | name => $method_name, | ||||
| 98 | roles => [ $role1->name, $role2->name ], | ||||
| 99 | ); | ||||
| 100 | } | ||||
| 101 | else { | ||||
| 102 | $role2->add_method( | ||||
| 103 | $method_name, | ||||
| 104 | $method, | ||||
| 105 | ); | ||||
| 106 | } | ||||
| 107 | } | ||||
| 108 | |||||
| 109 | next unless $self->is_method_aliased($method_name); | ||||
| 110 | |||||
| 111 | my $aliased_method_name = $self->get_method_aliases->{$method_name}; | ||||
| 112 | |||||
| 113 | my $role2_method = $role2->get_method($aliased_method_name); | ||||
| 114 | |||||
| 115 | if ( $role2_method | ||||
| 116 | && $role2_method->body != $method->body ) { | ||||
| 117 | |||||
| 118 | require Moose; | ||||
| 119 | Moose->throw_error( | ||||
| 120 | "Cannot create a method alias if a local method of the same name exists" | ||||
| 121 | ); | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | $role2->add_method( | ||||
| 125 | $aliased_method_name, | ||||
| 126 | $role1->get_method($method_name) | ||||
| 127 | ); | ||||
| 128 | |||||
| 129 | if ( !$role2->has_method($method_name) ) { | ||||
| 130 | $role2->add_required_methods($method_name) | ||||
| 131 | unless $self->is_method_excluded($method_name); | ||||
| 132 | } | ||||
| 133 | } | ||||
| 134 | } | ||||
| 135 | |||||
| 136 | sub apply_override_method_modifiers { | ||||
| 137 | my ($self, $role1, $role2) = @_; | ||||
| 138 | foreach my $method_name ($role1->get_method_modifier_list('override')) { | ||||
| 139 | # it if it has one already then ... | ||||
| 140 | if ($role2->has_method($method_name)) { | ||||
| 141 | # if it is being composed into another role | ||||
| 142 | # we have a conflict here, because you cannot | ||||
| 143 | # combine an overridden method with a locally | ||||
| 144 | # defined one | ||||
| 145 | require Moose; | ||||
| 146 | Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . | ||||
| 147 | "during composition (A local method of the same name as been found). This " . | ||||
| 148 | "is fatal error."); | ||||
| 149 | } | ||||
| 150 | else { | ||||
| 151 | # if we are a role, we need to make sure | ||||
| 152 | # we dont have a conflict with the role | ||||
| 153 | # we are composing into | ||||
| 154 | if ($role2->has_override_method_modifier($method_name) && | ||||
| 155 | $role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) { | ||||
| 156 | |||||
| 157 | require Moose; | ||||
| 158 | Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " . | ||||
| 159 | "during composition (Two 'override' methods of the same name encountered). " . | ||||
| 160 | "This is fatal error."); | ||||
| 161 | } | ||||
| 162 | else { | ||||
| 163 | # if there is no conflict, | ||||
| 164 | # just add it to the role | ||||
| 165 | $role2->add_override_method_modifier( | ||||
| 166 | $method_name, | ||||
| 167 | $role1->get_override_method_modifier($method_name) | ||||
| 168 | ); | ||||
| 169 | } | ||||
| 170 | } | ||||
| 171 | } | ||||
| 172 | } | ||||
| 173 | |||||
| 174 | sub apply_method_modifiers { | ||||
| 175 | my ($self, $modifier_type, $role1, $role2) = @_; | ||||
| 176 | my $add = "add_${modifier_type}_method_modifier"; | ||||
| 177 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
| 178 | foreach my $method_name ($role1->get_method_modifier_list($modifier_type)) { | ||||
| 179 | $role2->$add( | ||||
| 180 | $method_name, | ||||
| 181 | $_ | ||||
| 182 | ) foreach $role1->$get($method_name); | ||||
| 183 | } | ||||
| 184 | } | ||||
| 185 | |||||
| 186 | |||||
| 187 | 1 | 3µs | 1; | ||
| 188 | |||||
| 189 | # ABSTRACT: Compose a role into another role | ||||
| 190 | |||||
| - - | |||||
| 193 | =pod | ||||
| 194 | |||||
| 195 | =head1 NAME | ||||
| 196 | |||||
| 197 | Moose::Meta::Role::Application::ToRole - Compose a role into another role | ||||
| 198 | |||||
| 199 | =head1 VERSION | ||||
| 200 | |||||
| 201 | version 2.0602 | ||||
| 202 | |||||
| 203 | =head1 DESCRIPTION | ||||
| 204 | |||||
| 205 | =head2 METHODS | ||||
| 206 | |||||
| 207 | =over 4 | ||||
| 208 | |||||
| 209 | =item B<new> | ||||
| 210 | |||||
| 211 | =item B<meta> | ||||
| 212 | |||||
| 213 | =item B<apply> | ||||
| 214 | |||||
| 215 | =item B<check_role_exclusions> | ||||
| 216 | |||||
| 217 | =item B<check_required_methods> | ||||
| 218 | |||||
| 219 | =item B<check_required_attributes> | ||||
| 220 | |||||
| 221 | =item B<apply_attributes> | ||||
| 222 | |||||
| 223 | =item B<apply_methods> | ||||
| 224 | |||||
| 225 | =item B<apply_method_modifiers> | ||||
| 226 | |||||
| 227 | =item B<apply_override_method_modifiers> | ||||
| 228 | |||||
| 229 | =back | ||||
| 230 | |||||
| 231 | =head1 BUGS | ||||
| 232 | |||||
| 233 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 234 | |||||
| 235 | =head1 AUTHOR | ||||
| 236 | |||||
| 237 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
| 238 | |||||
| 239 | =head1 COPYRIGHT AND LICENSE | ||||
| 240 | |||||
| 241 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
| 242 | |||||
| 243 | This is free software; you can redistribute it and/or modify it under | ||||
| 244 | the same terms as the Perl 5 programming language system itself. | ||||
| 245 | |||||
| 246 | =cut | ||||
| 247 | |||||
| 248 | |||||
| 249 | __END__ |