| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/x86_64-linux/Moose/Meta/Role/Application/RoleSummation.pm |
| Statements | Executed 23 statements in 1.26ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 37µs | 77µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@13 |
| 1 | 1 | 1 | 10µs | 10µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@2 |
| 1 | 1 | 1 | 9µs | 25µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@10 |
| 1 | 1 | 1 | 9µs | 14µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@9 |
| 1 | 1 | 1 | 9µs | 570µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@11 |
| 1 | 1 | 1 | 8µs | 87µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@17 |
| 1 | 1 | 1 | 6µs | 6µs | Moose::Meta::Role::Application::RoleSummation::BEGIN@15 |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::__ANON__[:21] |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::apply_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::apply_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::apply_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::apply_override_method_modifiers |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::check_required_attributes |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::check_required_methods |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::check_role_exclusions |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::get_exclusions_for_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::get_method_aliases_for_role |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::is_aliased_method |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::is_method_aliased |
| 0 | 0 | 0 | 0s | 0s | Moose::Meta::Role::Application::RoleSummation::is_method_excluded |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Moose::Meta::Role::Application::RoleSummation; | ||||
| 2 | # spent 10µs within Moose::Meta::Role::Application::RoleSummation::BEGIN@2 which was called:
# once (10µs+0s) by Moose::BEGIN@39 at line 4 | ||||
| 3 | 1 | 4µs | $Moose::Meta::Role::Application::RoleSummation::AUTHORITY = 'cpan:STEVAN'; | ||
| 4 | 1 | 24µs | 1 | 10µs | } # spent 10µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@2 |
| 5 | { | ||||
| 6 | 2 | 1µs | $Moose::Meta::Role::Application::RoleSummation::VERSION = '2.0602'; | ||
| 7 | } | ||||
| 8 | |||||
| 9 | 3 | 20µs | 2 | 18µs | # spent 14µs (9+5) within Moose::Meta::Role::Application::RoleSummation::BEGIN@9 which was called:
# once (9µs+5µs) by Moose::BEGIN@39 at line 9 # spent 14µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@9
# spent 5µs making 1 call to strict::import |
| 10 | 3 | 19µs | 2 | 41µs | # spent 25µs (9+16) within Moose::Meta::Role::Application::RoleSummation::BEGIN@10 which was called:
# once (9µs+16µs) by Moose::BEGIN@39 at line 10 # spent 25µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@10
# spent 16µs making 1 call to warnings::import |
| 11 | 3 | 30µs | 2 | 1.13ms | # spent 570µs (9+561) within Moose::Meta::Role::Application::RoleSummation::BEGIN@11 which was called:
# once (9µs+561µs) by Moose::BEGIN@39 at line 11 # spent 570µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@11
# spent 561µs making 1 call to metaclass::import |
| 12 | |||||
| 13 | 3 | 23µs | 2 | 117µs | # spent 77µs (37+40) within Moose::Meta::Role::Application::RoleSummation::BEGIN@13 which was called:
# once (37µs+40µs) by Moose::BEGIN@39 at line 13 # spent 77µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@13
# spent 40µs making 1 call to Exporter::import |
| 14 | |||||
| 15 | 3 | 20µs | 1 | 6µs | # spent 6µs within Moose::Meta::Role::Application::RoleSummation::BEGIN@15 which was called:
# once (6µs+0s) by Moose::BEGIN@39 at line 15 # spent 6µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@15 |
| 16 | |||||
| 17 | 3 | 1.10ms | 2 | 166µs | # spent 87µs (8+79) within Moose::Meta::Role::Application::RoleSummation::BEGIN@17 which was called:
# once (8µs+79µs) by Moose::BEGIN@39 at line 17 # spent 87µs making 1 call to Moose::Meta::Role::Application::RoleSummation::BEGIN@17
# spent 79µs making 1 call to base::import |
| 18 | |||||
| 19 | __PACKAGE__->meta->add_attribute('role_params' => ( | ||||
| 20 | reader => 'role_params', | ||||
| 21 | default => sub { {} }, | ||||
| 22 | 1 | 8µs | 3 | 535µs | Class::MOP::_definition_context(), # spent 502µs making 1 call to Class::MOP::Mixin::HasAttributes::add_attribute
# spent 23µs making 1 call to Moose::Meta::Role::Application::RoleSummation::meta
# spent 10µs making 1 call to Class::MOP::_definition_context |
| 23 | )); | ||||
| 24 | |||||
| 25 | sub get_exclusions_for_role { | ||||
| 26 | my ($self, $role) = @_; | ||||
| 27 | $role = $role->name if blessed $role; | ||||
| 28 | my $excludes_key = exists $self->role_params->{$role}->{'-excludes'} ? | ||||
| 29 | '-excludes' : 'excludes'; | ||||
| 30 | if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$excludes_key}) { | ||||
| 31 | if (ref $self->role_params->{$role}->{$excludes_key} eq 'ARRAY') { | ||||
| 32 | return $self->role_params->{$role}->{$excludes_key}; | ||||
| 33 | } | ||||
| 34 | return [ $self->role_params->{$role}->{$excludes_key} ]; | ||||
| 35 | } | ||||
| 36 | return []; | ||||
| 37 | } | ||||
| 38 | |||||
| 39 | sub get_method_aliases_for_role { | ||||
| 40 | my ($self, $role) = @_; | ||||
| 41 | $role = $role->name if blessed $role; | ||||
| 42 | my $alias_key = exists $self->role_params->{$role}->{'-alias'} ? | ||||
| 43 | '-alias' : 'alias'; | ||||
| 44 | if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$alias_key}) { | ||||
| 45 | return $self->role_params->{$role}->{$alias_key}; | ||||
| 46 | } | ||||
| 47 | return {}; | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | sub is_method_excluded { | ||||
| 51 | my ($self, $role, $method_name) = @_; | ||||
| 52 | foreach ($self->get_exclusions_for_role($role->name)) { | ||||
| 53 | return 1 if $_ eq $method_name; | ||||
| 54 | } | ||||
| 55 | return 0; | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | sub is_method_aliased { | ||||
| 59 | my ($self, $role, $method_name) = @_; | ||||
| 60 | exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0 | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | sub is_aliased_method { | ||||
| 64 | my ($self, $role, $method_name) = @_; | ||||
| 65 | my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)}; | ||||
| 66 | exists $aliased_names{$method_name} ? 1 : 0; | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | sub check_role_exclusions { | ||||
| 70 | my ($self, $c) = @_; | ||||
| 71 | |||||
| 72 | my %excluded_roles; | ||||
| 73 | for my $role (@{ $c->get_roles }) { | ||||
| 74 | my $name = $role->name; | ||||
| 75 | |||||
| 76 | for my $excluded ($role->get_excluded_roles_list) { | ||||
| 77 | push @{ $excluded_roles{$excluded} }, $name; | ||||
| 78 | } | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | foreach my $role (@{$c->get_roles}) { | ||||
| 82 | foreach my $excluded (keys %excluded_roles) { | ||||
| 83 | next unless $role->does_role($excluded); | ||||
| 84 | |||||
| 85 | my @excluding = @{ $excluded_roles{$excluded} }; | ||||
| 86 | |||||
| 87 | require Moose; | ||||
| 88 | Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded); | ||||
| 89 | } | ||||
| 90 | } | ||||
| 91 | |||||
| 92 | $c->add_excluded_roles(keys %excluded_roles); | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | sub check_required_methods { | ||||
| 96 | my ($self, $c) = @_; | ||||
| 97 | |||||
| 98 | my %all_required_methods = | ||||
| 99 | map { $_->name => $_ } | ||||
| 100 | map { $_->get_required_method_list } | ||||
| 101 | @{$c->get_roles}; | ||||
| 102 | |||||
| 103 | foreach my $role (@{$c->get_roles}) { | ||||
| 104 | foreach my $required (keys %all_required_methods) { | ||||
| 105 | |||||
| 106 | delete $all_required_methods{$required} | ||||
| 107 | if $role->has_method($required) | ||||
| 108 | || $self->is_aliased_method($role, $required); | ||||
| 109 | } | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | $c->add_required_methods(values %all_required_methods); | ||||
| 113 | } | ||||
| 114 | |||||
| 115 | sub check_required_attributes { | ||||
| 116 | |||||
| 117 | } | ||||
| 118 | |||||
| 119 | sub apply_attributes { | ||||
| 120 | my ($self, $c) = @_; | ||||
| 121 | |||||
| 122 | my @all_attributes; | ||||
| 123 | |||||
| 124 | for my $role ( @{ $c->get_roles } ) { | ||||
| 125 | push @all_attributes, | ||||
| 126 | map { $role->get_attribute($_) } $role->get_attribute_list; | ||||
| 127 | } | ||||
| 128 | |||||
| 129 | my %seen; | ||||
| 130 | foreach my $attr (@all_attributes) { | ||||
| 131 | my $name = $attr->name; | ||||
| 132 | |||||
| 133 | if ( exists $seen{$name} ) { | ||||
| 134 | next if $seen{$name}->is_same_as($attr); | ||||
| 135 | |||||
| 136 | my $role1 = $seen{$name}->associated_role->name; | ||||
| 137 | my $role2 = $attr->associated_role->name; | ||||
| 138 | |||||
| 139 | require Moose; | ||||
| 140 | Moose->throw_error( | ||||
| 141 | "We have encountered an attribute conflict with '$name' " | ||||
| 142 | . "during role composition. " | ||||
| 143 | . " This attribute is defined in both $role1 and $role2." | ||||
| 144 | . " This is a fatal error and cannot be disambiguated." ); | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | $seen{$name} = $attr; | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | foreach my $attr (@all_attributes) { | ||||
| 151 | $c->add_attribute( $attr->clone ); | ||||
| 152 | } | ||||
| 153 | } | ||||
| 154 | |||||
| 155 | sub apply_methods { | ||||
| 156 | my ($self, $c) = @_; | ||||
| 157 | |||||
| 158 | my @all_methods = map { | ||||
| 159 | my $role = $_; | ||||
| 160 | my $aliases = $self->get_method_aliases_for_role($role); | ||||
| 161 | my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) }; | ||||
| 162 | ( | ||||
| 163 | (map { | ||||
| 164 | exists $excludes{$_} ? () : | ||||
| 165 | +{ | ||||
| 166 | role => $role, | ||||
| 167 | name => $_, | ||||
| 168 | method => $role->get_method($_), | ||||
| 169 | } | ||||
| 170 | } map { $_->name } | ||||
| 171 | grep { !$_->isa('Class::MOP::Method::Meta') } | ||||
| 172 | $role->_get_local_methods), | ||||
| 173 | (map { | ||||
| 174 | +{ | ||||
| 175 | role => $role, | ||||
| 176 | name => $aliases->{$_}, | ||||
| 177 | method => $role->get_method($_), | ||||
| 178 | } | ||||
| 179 | } keys %$aliases) | ||||
| 180 | ); | ||||
| 181 | } @{$c->get_roles}; | ||||
| 182 | |||||
| 183 | my (%seen, %conflicts, %method_map); | ||||
| 184 | foreach my $method (@all_methods) { | ||||
| 185 | next if $conflicts{$method->{name}}; | ||||
| 186 | my $seen = $seen{$method->{name}}; | ||||
| 187 | |||||
| 188 | if ($seen) { | ||||
| 189 | if ($seen->{method}->body != $method->{method}->body) { | ||||
| 190 | $c->add_conflicting_method( | ||||
| 191 | name => $method->{name}, | ||||
| 192 | roles => [$method->{role}->name, $seen->{role}->name], | ||||
| 193 | ); | ||||
| 194 | |||||
| 195 | delete $method_map{$method->{name}}; | ||||
| 196 | $conflicts{$method->{name}} = 1; | ||||
| 197 | next; | ||||
| 198 | } | ||||
| 199 | } | ||||
| 200 | |||||
| 201 | $seen{$method->{name}} = $method; | ||||
| 202 | $method_map{$method->{name}} = $method->{method}; | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | $c->add_method($_ => $method_map{$_}) for keys %method_map; | ||||
| 206 | } | ||||
| 207 | |||||
| 208 | sub apply_override_method_modifiers { | ||||
| 209 | my ($self, $c) = @_; | ||||
| 210 | |||||
| 211 | my @all_overrides = map { | ||||
| 212 | my $role = $_; | ||||
| 213 | map { | ||||
| 214 | +{ | ||||
| 215 | name => $_, | ||||
| 216 | method => $role->get_override_method_modifier($_), | ||||
| 217 | } | ||||
| 218 | } $role->get_method_modifier_list('override'); | ||||
| 219 | } @{$c->get_roles}; | ||||
| 220 | |||||
| 221 | my %seen; | ||||
| 222 | foreach my $override (@all_overrides) { | ||||
| 223 | if ( $c->has_method($override->{name}) ){ | ||||
| 224 | require Moose; | ||||
| 225 | Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " . | ||||
| 226 | "during composition (A local method of the same name as been found). This " . | ||||
| 227 | "is fatal error." ) | ||||
| 228 | } | ||||
| 229 | if (exists $seen{$override->{name}}) { | ||||
| 230 | if ( $seen{$override->{name}} != $override->{method} ) { | ||||
| 231 | require Moose; | ||||
| 232 | Moose->throw_error( "We have encountered an 'override' method conflict during " . | ||||
| 233 | "composition (Two 'override' methods of the same name encountered). " . | ||||
| 234 | "This is fatal error.") | ||||
| 235 | } | ||||
| 236 | } | ||||
| 237 | $seen{$override->{name}} = $override->{method}; | ||||
| 238 | } | ||||
| 239 | |||||
| 240 | $c->add_override_method_modifier( | ||||
| 241 | $_->{name}, $_->{method} | ||||
| 242 | ) for @all_overrides; | ||||
| 243 | |||||
| 244 | } | ||||
| 245 | |||||
| 246 | sub apply_method_modifiers { | ||||
| 247 | my ($self, $modifier_type, $c) = @_; | ||||
| 248 | my $add = "add_${modifier_type}_method_modifier"; | ||||
| 249 | my $get = "get_${modifier_type}_method_modifiers"; | ||||
| 250 | foreach my $role (@{$c->get_roles}) { | ||||
| 251 | foreach my $method_name ($role->get_method_modifier_list($modifier_type)) { | ||||
| 252 | $c->$add( | ||||
| 253 | $method_name, | ||||
| 254 | $_ | ||||
| 255 | ) foreach $role->$get($method_name); | ||||
| 256 | } | ||||
| 257 | } | ||||
| 258 | } | ||||
| 259 | |||||
| 260 | 1 | 7µs | 1; | ||
| 261 | |||||
| 262 | # ABSTRACT: Combine two or more roles | ||||
| 263 | |||||
| - - | |||||
| 266 | =pod | ||||
| 267 | |||||
| 268 | =head1 NAME | ||||
| 269 | |||||
| 270 | Moose::Meta::Role::Application::RoleSummation - Combine two or more roles | ||||
| 271 | |||||
| 272 | =head1 VERSION | ||||
| 273 | |||||
| 274 | version 2.0602 | ||||
| 275 | |||||
| 276 | =head1 DESCRIPTION | ||||
| 277 | |||||
| 278 | Summation composes two traits, forming the union of non-conflicting | ||||
| 279 | bindings and 'disabling' the conflicting bindings | ||||
| 280 | |||||
| 281 | =head2 METHODS | ||||
| 282 | |||||
| 283 | =over 4 | ||||
| 284 | |||||
| 285 | =item B<new> | ||||
| 286 | |||||
| 287 | =item B<meta> | ||||
| 288 | |||||
| 289 | =item B<role_params> | ||||
| 290 | |||||
| 291 | =item B<get_exclusions_for_role> | ||||
| 292 | |||||
| 293 | =item B<get_method_aliases_for_role> | ||||
| 294 | |||||
| 295 | =item B<is_aliased_method> | ||||
| 296 | |||||
| 297 | =item B<is_method_aliased> | ||||
| 298 | |||||
| 299 | =item B<is_method_excluded> | ||||
| 300 | |||||
| 301 | =item B<apply> | ||||
| 302 | |||||
| 303 | =item B<check_role_exclusions> | ||||
| 304 | |||||
| 305 | =item B<check_required_methods> | ||||
| 306 | |||||
| 307 | =item B<check_required_attributes> | ||||
| 308 | |||||
| 309 | =item B<apply_attributes> | ||||
| 310 | |||||
| 311 | =item B<apply_methods> | ||||
| 312 | |||||
| 313 | =item B<apply_method_modifiers> | ||||
| 314 | |||||
| 315 | =item B<apply_override_method_modifiers> | ||||
| 316 | |||||
| 317 | =back | ||||
| 318 | |||||
| 319 | =head1 BUGS | ||||
| 320 | |||||
| 321 | See L<Moose/BUGS> for details on reporting bugs. | ||||
| 322 | |||||
| 323 | =head1 AUTHOR | ||||
| 324 | |||||
| 325 | Moose is maintained by the Moose Cabal, along with the help of many contributors. See L<Moose/CABAL> and L<Moose/CONTRIBUTORS> for details. | ||||
| 326 | |||||
| 327 | =head1 COPYRIGHT AND LICENSE | ||||
| 328 | |||||
| 329 | This software is copyright (c) 2012 by Infinity Interactive, Inc.. | ||||
| 330 | |||||
| 331 | This is free software; you can redistribute it and/or modify it under | ||||
| 332 | the same terms as the Perl 5 programming language system itself. | ||||
| 333 | |||||
| 334 | =cut | ||||
| 335 | |||||
| 336 | |||||
| 337 | __END__ |