-
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;
# 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
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(@_);
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;
}
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;
}
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;
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')) {
$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 :)
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};
=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