my $name;
if (ref($alias)) {
reftype($alias) eq 'ARRAY'
- or Moose->throw_error(reftype($alias) . " references are not "
+ or Moose::Util::throw(reftype($alias) . " references are not "
. "valid arguments to the 'trait_aliases' "
. "option");
_apply_meta_traits( $CALLER, $traits, $meta_lookup );
}
elsif ( @{$traits} ) {
- require Moose;
- Moose->throw_error(
+ Moose::Util::throw(
"Cannot provide traits when $class does not have an init_meta() method"
);
}
my $meta = $meta_lookup->($class);
my $type = ( split /::/, ref $meta )[-1]
- or Moose->throw_error(
+ or Moose::Util::throw(
'Cannot determine metaclass type for trait application . Meta isa '
. ref $meta );
);
if ($meta->find_method_by_name('register_implementation')) {
my $class = $meta->name->register_implementation;
- Moose->throw_error(
+ Moose::Util::throw(
"An implementation for $trait_name already exists " .
"(found '$class' when trying to register '$trait_class')"
);
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')) {
my @excluding = @{ $excluded_roles{$excluded} };
- require Moose;
- Moose->throw_error(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded);
+ Moose::Util::throw(sprintf "Conflict detected: Role%s %s exclude%s role '%s'", (@excluding == 1 ? '' : 's'), join(', ', @excluding), (@excluding == 1 ? 's' : ''), $excluded);
}
}
my $role1 = $seen{$name}->associated_role->name;
my $role2 = $attr->associated_role->name;
- require Moose;
- Moose->throw_error(
+ Moose::Util::throw(
"We have encountered an attribute conflict with '$name' "
. "during role composition. "
. " This attribute is defined in both $role1 and $role2."
my %seen;
foreach my $override (@all_overrides) {
if ( $c->has_method($override->{name}) ){
- require Moose;
- Moose->throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " .
+ Moose::Util::throw( "Role '" . $c->name . "' has encountered an 'override' method conflict " .
"during composition (A local method of the same name as been found). This " .
"is fatal error." )
}
if (exists $seen{$override->{name}}) {
if ( $seen{$override->{name}} != $override->{method} ) {
- require Moose;
- Moose->throw_error( "We have encountered an 'override' method conflict during " .
+ Moose::Util::throw( "We have encountered an 'override' method conflict during " .
"composition (Two 'override' methods of the same name encountered). " .
"This is fatal error.")
}
sub check_role_exclusions {
my ($self, $role1, $role2) = @_;
if ( $role2->excludes_role($role1->name) ) {
- require Moose;
- Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'");
+ Moose::Util::throw("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'");
}
foreach my $excluded_role_name ($role1->get_excluded_roles_list) {
if ( $role2->does_role($excluded_role_name) ) {
- require Moose;
- Moose->throw_error("The role " . $role2->name . " does the excluded role '$excluded_role_name'");
+ Moose::Util::throw("The role " . $role2->name . " does the excluded role '$excluded_role_name'");
}
$role2->add_excluded_roles($excluded_role_name);
}
my $role2_name = $role2->name;
- require Moose;
- Moose->throw_error( "Role '"
+ Moose::Util::throw( "Role '"
. $role1->name
. "' has encountered an attribute conflict"
. " while being composed into '$role2_name'."
if ( $role2_method
&& $role2_method->body != $method->body ) {
- require Moose;
- Moose->throw_error(
+ Moose::Util::throw(
"Cannot create a method alias if a local method of the same name exists"
);
}
# we have a conflict here, because you cannot
# combine an overridden method with a locally
# defined one
- require Moose;
- Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
+ Moose::Util::throw("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
"during composition (A local method of the same name as been found). This " .
"is fatal error.");
}
if ($role2->has_override_method_modifier($method_name) &&
$role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) {
- require Moose;
- Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
+ Moose::Util::throw("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
"during composition (Two 'override' methods of the same name encountered). " .
"This is fatal error.");
}
# the roles param is required ...
foreach ( @{$params{roles}} ) {
unless ( $_->isa('Moose::Meta::Role') ) {
- require Moose;
- Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_");
+ Moose::Util::throw("The list of roles must be instances of Moose::Meta::Role, not $_");
}
}
my ($self, $method_name, $method) = @_;
unless ( defined $method_name && $method_name ) {
- Moose->throw_error("You must define a method name");
+ Moose::Util::throw("You must define a method name");
}
my $body;
sub reinitialize {
my ( $class, $old_meta, @args ) = @_;
- Moose->throw_error(
+ Moose::Util::throw(
'Moose::Meta::Role::Composite instances can only be reinitialized from an existing metaclass instance'
)
if !blessed $old_meta
my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
unless ( defined $type_constraint ) {
- require Moose;
- Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
+ Moose::Util::throw("Could not find the type constraint ($constraint_name) to coerce from");
}
push @coercions => [
my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2);
if ( exists $has_coercion{$constraint_name} ) {
- require Moose;
- Moose->throw_error("A coercion action already exists for '$constraint_name'")
+ Moose::Util::throw("A coercion action already exists for '$constraint_name'")
}
push @{$coercion_map} => ($constraint_name, $action);
my $type_constraint = $self->type_constraint;
(blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union'))
- || Moose->throw_error("You can only create a Moose::Meta::TypeCoercion::Union for a " .
+ || Moose::Util::throw("You can only create a Moose::Meta::TypeCoercion::Union for a " .
"Moose::Meta::TypeConstraint::Union, not a $type_constraint");
$self->_compiled_type_coercion(
sub has_coercion_for_type { 0 }
sub add_type_coercions {
- require Moose;
- Moose->throw_error("Cannot add additional type coercions to Union types");
+ Moose::Util::throw("Cannot add additional type coercions to Union types");
}
1;
my $coercion = $self->coercion;
unless ($coercion) {
- require Moose;
- Moose->throw_error("Cannot coerce without a type coercion");
+ Moose::Util::throw("Cannot coerce without a type coercion");
}
return $_[0] if $self->check($_[0]);
my $coercion = $self->coercion;
unless ($coercion) {
- require Moose;
- Moose->throw_error("Cannot coerce without a type coercion");
+ Moose::Util::throw("Cannot coerce without a type coercion");
}
return $_[0] if $self->check($_[0]);
my $self = shift;
unless ( $self->can_be_inlined ) {
- require Moose;
- Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
+ Moose::Util::throw( 'Cannot inline a type constraint check for ' . $self->name );
}
if ( $self->has_parent && $self->constraint == $null_constraint ) {
my $check = $self->constraint;
unless ( defined $check ) {
- require Moose;
- Moose->throw_error( "Could not compile type constraint '"
+ Moose::Util::throw( "Could not compile type constraint '"
. $self->name
. "' because no constraint check" );
}
my $type_constraint = $self->hand_optimized_type_constraint;
unless ( ref $type_constraint ) {
- require Moose;
- Moose->throw_error("Hand optimized type constraint is not a code reference");
+ Moose::Util::throw("Hand optimized type constraint is not a code reference");
}
return $type_constraint;
$args{inlined} = $inliner;
if ( scalar @{ $args{values} } < 1 ) {
- require Moose;
- Moose->throw_error("You must have at least one value to enumerate through");
+ Moose::Util::throw("You must have at least one value to enumerate through");
}
for (@{ $args{values} }) {
if (!defined($_)) {
- require Moose;
- Moose->throw_error("Enum values must be strings, not undef");
+ Moose::Util::throw("Enum values must be strings, not undef");
}
elsif (ref($_)) {
- require Moose;
- Moose->throw_error("Enum values must be strings, not '$_'");
+ Moose::Util::throw("Enum values must be strings, not '$_'");
}
}
use base 'Moose::Meta::TypeConstraint';
use Moose::Meta::TypeConstraint::Parameterized;
use Moose::Util::TypeConstraints ();
+use Moose::Util ();
__PACKAGE__->meta->add_attribute('constraint_generator' => (
accessor => 'constraint_generator',
if(my $parent = $self->parent) {
if($parent->can('type_parameter')) {
unless ( $contained_tc->is_a_type_of($parent->type_parameter) ) {
- require Moose;
- Moose->throw_error("$type_parameter is not a subtype of ".$parent->type_parameter);
+ Moose::Util::throw("$type_parameter is not a subtype of ".$parent->type_parameter);
}
}
}
);
}
else {
- require Moose;
- Moose->throw_error("The type parameter must be a Moose meta type");
+ Moose::Util::throw("The type parameter must be a Moose meta type");
}
}
my $self = shift;
unless ( $self->has_type_parameter ) {
- require Moose;
- Moose->throw_error("You cannot create a Higher Order type without a type parameter");
+ Moose::Util::throw("You cannot create a Higher Order type without a type parameter");
}
my $type_parameter = $self->type_parameter;
unless ( blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint') ) {
- require Moose;
- Moose->throw_error("The type parameter must be a Moose meta type");
+ Moose::Util::throw("The type parameter must be a Moose meta type");
}
foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
# if we get here, then we couldn't
# find a way to parameterize this type
- require Moose;
- Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
+ Moose::Util::throw("The " . $self->name . " constraint cannot be used, because "
. $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
}
my ($self, $type) = @_;
unless ( $type && blessed $type && $type->isa('Moose::Meta::TypeConstraint') ) {
- require Moose;
- Moose->throw_error("No type supplied / type is not a valid type constraint");
+ Moose::Util::throw("No type supplied / type is not a valid type constraint");
}
$self->type_constraints->{$type->name} = $type;
use MRO::Compat ();
use Scalar::Util ();
use Try::Tiny ();
+use Moose::Util ();
use if ( not our $__mx_is_compiled ), 'Moose::Meta::Class';
use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
my $role = $args{for_class};
unless ($role) {
- require Moose;
- Moose->throw_error("Cannot call init_meta without specifying a for_class");
+ Moose::Util::throw("Cannot call init_meta without specifying a for_class");
}
my $metaclass = $args{metaclass} || "Moose::Meta::Role";
my $meta_name = exists $args{meta_name} ? $args{meta_name} : 'meta';
- Moose->throw_error("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)")
+ Moose::Util::throw("The Metaclass $metaclass must be loaded. (Perhaps you forgot to 'use $metaclass'?)")
unless is_class_loaded($metaclass);
- Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.")
+ Moose::Util::throw("The Metaclass $metaclass must be a subclass of Moose::Meta::Role.")
unless $metaclass->isa('Moose::Meta::Role');
# make a subtype for each Moose role
unless ( $meta->isa("Moose::Meta::Role") ) {
my $error_message = "$role already has a metaclass, but it does not inherit $metaclass ($meta).";
if ( $meta->isa('Moose::Meta::Class') ) {
- Moose->throw_error($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.');
+ Moose::Util::throw($error_message . ' You cannot make the same thing a role and a class. Remove either Moose or Moose::Role.');
} else {
- Moose->throw_error($error_message);
+ Moose::Util::throw($error_message);
}
}
}