s/statis/stasis/ in Moose/Meta/Role.pm
[gitmo/Moose.git] / lib / Moose / Meta / Role.pm
index 4e6eee8..0f96d22 100644 (file)
@@ -1,10 +1,10 @@
-
 package Moose::Meta::Role;
 
 use strict;
 use warnings;
 use metaclass;
 
+use Class::Load qw(load_class);
 use Scalar::Util 'blessed';
 use Carp         'confess';
 use Devel::GlobalDestruction 'in_global_destruction';
@@ -43,7 +43,7 @@ my $META = __PACKAGE__->meta;
 
 # NOTE:
 # since roles are lazy, we hold all the attributes
-# of the individual role in 'statis' until which
+# of the individual role in 'stasis' until which
 # time when it is applied to a class. This means
 # keeping a lot of things in hash maps, so we are
 # using a little of that meta-programmin' magic
@@ -82,7 +82,8 @@ foreach my $action (
     # create the attribute
     $META->add_attribute($action->{name} => (
         reader  => $attr_reader,
-        default => sub { {} }
+        default => sub { {} },
+        Class::MOP::_definition_context(),
     ));
 
     # create some helper methods
@@ -121,42 +122,49 @@ $META->add_attribute(
     'method_metaclass',
     reader  => 'method_metaclass',
     default => 'Moose::Meta::Role::Method',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'required_method_metaclass',
     reader  => 'required_method_metaclass',
     default => 'Moose::Meta::Role::Method::Required',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'conflicting_method_metaclass',
     reader  => 'conflicting_method_metaclass',
     default => 'Moose::Meta::Role::Method::Conflicting',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'application_to_class_class',
     reader  => 'application_to_class_class',
     default => 'Moose::Meta::Role::Application::ToClass',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'application_to_role_class',
     reader  => 'application_to_role_class',
     default => 'Moose::Meta::Role::Application::ToRole',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'application_to_instance_class',
     reader  => 'application_to_instance_class',
     default => 'Moose::Meta::Role::Application::ToInstance',
+    Class::MOP::_definition_context(),
 );
 
 $META->add_attribute(
     'applied_attribute_metaclass',
     reader  => 'applied_attribute_metaclass',
     default => 'Moose::Meta::Attribute',
+    Class::MOP::_definition_context(),
 );
 
 # More or less copied from Moose::Meta::Class
@@ -291,7 +299,8 @@ foreach my $modifier_type (qw[ before around after ]) {
     # create the attribute ...
     $META->add_attribute("${modifier_type}_method_modifiers" => (
         reader  => $attr_reader,
-        default => sub { {} }
+        default => sub { {} },
+        Class::MOP::_definition_context(),
     ));
 
     # and some helper methods ...
@@ -336,7 +345,8 @@ foreach my $modifier_type (qw[ before around after ]) {
 
 $META->add_attribute('override_method_modifiers' => (
     reader  => 'get_override_method_modifiers_map',
-    default => sub { {} }
+    default => sub { {} },
+    Class::MOP::_definition_context(),
 ));
 
 # NOTE:
@@ -381,7 +391,8 @@ sub _meta_method_class { 'Moose::Meta::Method::Meta' }
 
 $META->add_attribute('roles' => (
     reader  => 'get_roles',
-    default => sub { [] }
+    default => sub { [] },
+    Class::MOP::_definition_context(),
 ));
 
 sub add_role {
@@ -439,30 +450,7 @@ sub apply {
         $application_class = $self->application_to_instance_class;
     }
 
-    Class::MOP::load_class($application_class);
-
-    my $deprecation_check = 0;
-
-    if ( exists $args{excludes} && !exists $args{'-excludes'} ) {
-        $args{'-excludes'} = delete $args{excludes};
-        $deprecation_check = 1;
-    }
-    if ( exists $args{alias} && !exists $args{'-alias'} ) {
-        $args{'-alias'} = delete $args{alias};
-        $deprecation_check = 1;
-    }
-
-    if ( $deprecation_check ) {
-        Moose::Deprecated::deprecated(
-            feature => 'alias or excludes',
-            message =>
-                'The alias and excludes options for role application'.
-                ' have been renamed -alias and -excludes'.
-                " (${\$other->name} is consuming ${\$self->name}".
-                " - do you need to upgrade ${\$other->name}?).".
-                ' This will be an error in Moose 2.0200.'
-        );
-    }
+    load_class($application_class);
 
     if ( exists $args{'-excludes'} ) {
         # I wish we had coercion here :)
@@ -582,10 +570,50 @@ sub is_anon_role     { shift->is_anon(@_)     }
 sub _anon_cache_key {
     my $class = shift;
     my %options = @_;
+
+    # XXX fix this duplication (see MMC::_anon_cache_key
+    my $roles = Data::OptList::mkopt(($options{roles} || []), {
+        moniker  => 'role',
+        val_test => sub { ref($_[0]) eq 'HASH' },
+    });
+
+    my @role_keys;
+    for my $role_spec (@$roles) {
+        my ($role, $params) = @$role_spec;
+        $params = { %$params };
+
+        my $key = blessed($role) ? $role->name : $role;
+
+        if ($params && %$params) {
+            my $alias    = delete $params->{'-alias'}
+                        || delete $params->{'alias'}
+                        || {};
+            my $excludes = delete $params->{'-excludes'}
+                        || delete $params->{'excludes'}
+                        || [];
+            $excludes = [$excludes] unless ref($excludes) eq 'ARRAY';
+
+            if (%$params) {
+                warn "Roles with parameters cannot be cached. Consider "
+                   . "applying the parameters before calling "
+                   . "create_anon_class, or using 'weaken => 0' instead";
+                return;
+            }
+
+            my $alias_key = join('%',
+                map { $_ => $alias->{$_} } sort keys %$alias
+            );
+            my $excludes_key = join('%',
+                sort @$excludes
+            );
+            $key .= '<' . join('+', 'a', $alias_key, 'e', $excludes_key) . '>';
+        }
+
+        push @role_keys, $key;
+    }
+
     # Makes something like Role|Role::1
-    return join '=' => (
-        join( '|', sort @{ $options{roles} || [] } ),
-    );
+    return join('|', sort @role_keys);
 }
 
 #####################################################################