Convert Moose->throw_error to Moose::Util::throw
[gitmo/Moose.git] / lib / Moose / Meta / Role.pm
index c251b65..eb31161 100644 (file)
@@ -1,12 +1,11 @@
-
 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';
 
 use Moose::Meta::Class;
@@ -43,7 +42,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
@@ -238,10 +237,10 @@ sub add_attribute {
 
     if (blessed $_[0] && ! $_[0]->isa('Moose::Meta::Role::Attribute') ) {
         my $class = ref $_[0];
-        Moose->throw_error( "Cannot add a $class as an attribute to a role" );
+        Moose::Util::throw( "Cannot add a $class as an attribute to a role" );
     }
     elsif (!blessed($_[0]) && defined($_[0]) && $_[0] =~ /^\+(.*)/) {
-        Moose->throw_error( "has '+attr' is not supported in roles" );
+        Moose::Util::throw( "has '+attr' is not supported in roles" );
     }
 
     return $self->SUPER::add_attribute(@_);
@@ -358,7 +357,7 @@ $META->add_attribute('override_method_modifiers' => (
 sub add_override_method_modifier {
     my ($self, $method_name, $method) = @_;
     (!$self->has_method($method_name))
-        || Moose->throw_error("Cannot add an override of method '$method_name' " .
+        || Moose::Util::throw("Cannot add an override of method '$method_name' " .
                    "because there is a local version of '$method_name'");
     $self->get_override_method_modifiers_map->{$method_name} = $method;
 }
@@ -398,7 +397,7 @@ $META->add_attribute('roles' => (
 sub add_role {
     my ($self, $role) = @_;
     (blessed($role) && $role->isa('Moose::Meta::Role'))
-        || Moose->throw_error("Roles must be instances of Moose::Meta::Role");
+        || Moose::Util::throw("Roles must be instances of Moose::Meta::Role");
     push @{$self->get_roles} => $role;
     $self->reset_package_cache_flag;
 }
@@ -416,7 +415,7 @@ sub calculate_all_roles {
 sub does_role {
     my ($self, $role) = @_;
     (defined $role)
-        || Moose->throw_error("You must supply a role name to look for");
+        || Moose::Util::throw("You must supply a role name to look for");
     my $role_name = blessed $role ? $role->name : $role;
     # if we are it,.. then return true
     return 1 if $role_name eq $self->name;
@@ -437,7 +436,7 @@ sub apply {
     my ($self, $other, %args) = @_;
 
     (blessed($other))
-        || Moose->throw_error("You must pass in an blessed instance");
+        || Moose::Util::throw("You must pass in an blessed instance");
 
     my $application_class;
     if ($other->isa('Moose::Meta::Role')) {
@@ -450,7 +449,7 @@ sub apply {
         $application_class = $self->application_to_instance_class;
     }
 
-    Class::MOP::load_class($application_class);
+    load_class($application_class);
 
     if ( exists $args{'-excludes'} ) {
         # I wish we had coercion here :)
@@ -503,15 +502,15 @@ sub create {
     my %options = @args;
 
     (ref $options{attributes} eq 'HASH')
-        || confess "You must pass a HASH ref of attributes"
+        || Moose::Util::throw "You must pass a HASH ref of attributes"
             if exists $options{attributes};
 
     (ref $options{methods} eq 'HASH')
-        || confess "You must pass a HASH ref of methods"
+        || Moose::Util::throw "You must pass a HASH ref of methods"
             if exists $options{methods};
 
     (ref $options{roles} eq 'ARRAY')
-        || confess "You must pass an ARRAY ref of roles"
+        || Moose::Util::throw "You must pass an ARRAY ref of roles"
             if exists $options{roles};
 
     my $package      = delete $options{package};
@@ -904,6 +903,31 @@ This is quite likely to change in the future.
 
 =back
 
+=head2 Overload introspection and creation
+
+The methods for dealing with a role's overloads are all identical in API
+and behavior to the same methods in L<Class::MOP::Class>. Note that these are
+not particularly useful (yet), because overloads do not participate in role
+composition.
+
+=over 4
+
+=item B<< $metarole->is_overloaded >>
+
+=item B<< $metarole->get_overloaded_operator($op) >>
+
+=item B<< $metarole->has_overloaded_operator($op) >>
+
+=item B<< $metarole->get_overload_list >>
+
+=item B<< $metarole->get_all_overloaded_operators >>
+
+=item B<< $metarole->add_overloaded_operator($op, $impl) >>
+
+=item B<< $metarole->remove_overloaded_operator($op) >>
+
+=back
+
 =head2 Required methods
 
 =over 4