use Moose::Util::TypeConstraints;
use Moose::Util ();
-BEGIN { *throw_error = \&confess } # FIXME make this smarter
+sub throw_error {
+ # FIXME This
+ shift;
+ goto \&confess
+}
sub extends {
my $class = shift;
my %args = @_;
my $class = $args{for_class}
- or throw_error "Cannot call init_meta without specifying a for_class";
+ or Moose->throw_error("Cannot call init_meta without specifying a for_class");
my $base_class = $args{base_class} || 'Moose::Object';
my $metaclass = $args{metaclass} || 'Moose::Meta::Class';
- throw_error
- "The Metaclass $metaclass must be a subclass of Moose::Meta::Class."
+ Moose->throw_error("The Metaclass $metaclass must be a subclass of Moose::Meta::Class.")
unless $metaclass->isa('Moose::Meta::Class');
# make a subtype for each Moose class
if ( $meta = Class::MOP::get_metaclass_by_name($class) ) {
unless ( $meta->isa("Moose::Meta::Class") ) {
- throw_error "$class already has a metaclass, but it does not inherit $metaclass ($meta)";
+ Moose->throw_error("$class already has a metaclass, but it does not inherit $metaclass ($meta)");
}
} else {
# no metaclass, no 'meta' method
my $method_meta = $class->meta;
( blessed($method_meta) && $method_meta->isa('Moose::Meta::Class') )
- || throw_error "$class already has a &meta function, but it does not return a Moose::Meta::Class ($meta)";
+ || Moose->throw_error("$class already has a &meta function, but it does not return a Moose::Meta::Class ($meta)");
$meta = $method_meta;
}
_apply_meta_traits( $CALLER, $traits );
}
elsif ( @{$traits} ) {
- Moose::throw_error("Cannot provide traits when $class does not have an init_meta() method");
+ Moose->throw_error("Cannot provide traits when $class does not have an init_meta() method");
}
goto $exporter;
my $meta = $class->meta();
my $type = ( split /::/, ref $meta )[-1]
- or Moose::throw_error(
+ or Moose->throw_error(
'Cannot determine metaclass type for trait application . Meta isa '
. ref $meta );
# this was changed in 0.41, but broke MooseX::Singleton, so try to catch
# any other code using the original broken spelling
-sub intialize_body { Moose::throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") }
+sub intialize_body { Moose->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") }
sub initialize_body {
my $self = shift;
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->throw_error("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->throw_error("Roles must be instances of Moose::Meta::Role");
push @{$self->get_roles} => $role;
$self->reset_package_cache_flag;
}
sub does_role {
my ($self, $role_name) = @_;
(defined $role_name)
- || Moose::throw_error("You must supply a role name to look for");
+ || Moose->throw_error("You must supply a role name to look for");
# if we are it,.. then return true
return 1 if $role_name eq $self->name;
# otherwise.. check our children
my $body = delete $args{body}; # delete is for compat
('CODE' eq ref($body))
- || Moose::throw_error("Your code block must be a CODE reference");
+ || Moose->throw_error("Your code block must be a CODE reference");
$self->method_metaclass->wrap( $body => (
package_name => $self->name,
sub add_method {
my ($self, $method_name, $method) = @_;
(defined $method_name && $method_name)
- || Moose::throw_error("You must define a method name");
+ || Moose->throw_error("You must define a method name");
my $body;
if (blessed($method)) {
sub alias_method {
my ($self, $method_name, $method) = @_;
(defined $method_name && $method_name)
- || Moose::throw_error("You must define a method name");
+ || Moose->throw_error("You must define a method name");
my $body = (blessed($method) ? $method->body : $method);
('CODE' eq ref($body))
- || Moose::throw_error("Your code block must be a CODE reference");
+ || Moose->throw_error("Your code block must be a CODE reference");
$self->add_package_symbol(
{ sigil => '&', type => 'CODE', name => $method_name },
my ($self, $other, @args) = @_;
(blessed($other))
- || Moose::throw_error("You must pass in an blessed instance");
+ || Moose->throw_error("You must pass in an blessed instance");
if ($other->isa('Moose::Meta::Role')) {
require Moose::Meta::Role::Application::ToRole;
foreach my $role (@{$c->get_roles}) {
foreach my $excluded (@all_excluded_roles) {
- Moose::throw_error("Conflict detected: " . $role->name . " excludes role '" . $excluded . "'")
+ Moose->throw_error("Conflict detected: " . $role->name . " excludes role '" . $excluded . "'")
if $role->does_role($excluded);
}
}
my %seen;
foreach my $attr (@all_attributes) {
if (exists $seen{$attr->{name}}) {
- Moose::throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' "
+ Moose->throw_error("We have encountered an attribute conflict with '" . $attr->{name} . "' "
. "during composition. This is fatal error and cannot be disambiguated.")
if $seen{$attr->{name}} != $attr->{attr};
}
my %seen;
foreach my $override (@all_overrides) {
- Moose::throw_error( "Role '" . $c->name . "' has encountered an 'override' method conflict " .
+ Moose->throw_error( "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 $c->has_method($override->{name});
if (exists $seen{$override->{name}}) {
- Moose::throw_error( "We have encountered an 'override' method conflict during " .
+ Moose->throw_error( "We have encountered an 'override' method conflict during " .
"composition (Two 'override' methods of the same name encountered). " .
"This is fatal error.")
if $seen{$override->{name}} != $override->{method};
sub check_role_exclusions {
my ($self, $role1, $role2) = @_;
- Moose::throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'")
+ Moose->throw_error("Conflict detected: " . $role2->name . " excludes role '" . $role1->name . "'")
if $role2->excludes_role($role1->name);
foreach my $excluded_role_name ($role1->get_excluded_roles_list) {
- Moose::throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'")
+ Moose->throw_error("The class " . $role2->name . " does the excluded role '$excluded_role_name'")
if $role2->does_role($excluded_role_name);
$role2->add_excluded_roles($excluded_role_name);
}
if ($role2->has_attribute($attribute_name) &&
# make sure we haven't seen this one already too
$role2->get_attribute($attribute_name) != $role1->get_attribute($attribute_name)) {
- Moose::throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " .
+ Moose->throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " .
"during composition. This is fatal error and cannot be disambiguated.");
}
else {
if ($role2->has_method($aliased_method_name) &&
# and if they are not the same thing ...
$role2->get_method($aliased_method_name)->body != $role1->get_method($method_name)->body) {
- Moose::throw_error("Cannot create a method alias if a local method of the same name exists");
+ Moose->throw_error("Cannot create a method alias if a local method of the same name exists");
}
$role2->alias_method(
# we have a conflict here, because you cannot
# combine an overriden method with a locally
# defined one
- Moose::throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
+ Moose->throw_error("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.");
}
# we are composing into
if ($role2->has_override_method_modifier($method_name) &&
$role2->get_override_method_modifier($method_name) != $role2->get_override_method_modifier($method_name)) {
- Moose::throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
+ Moose->throw_error("Role '" . $role1->name . "' has encountered an 'override' method conflict " .
"during composition (Two 'override' methods of the same name encountered). " .
"This is fatal error.");
}
my ($class, %params) = @_;
# the roles param is required ...
($_->isa('Moose::Meta::Role'))
- || Moose::throw_error("The list of roles must be instances of Moose::Meta::Role, not $_")
+ || Moose->throw_error("The list of roles must be instances of Moose::Meta::Role, not $_")
foreach @{$params{roles}};
# and the name is created from the
# roles if one has not been provided
sub alias_method {
my ($self, $method_name, $method) = @_;
(defined $method_name && $method_name)
- || Moose::throw_error("You must define a method name");
+ || Moose->throw_error("You must define a method name");
# make sure to bless the
# method if nessecary
my ($constraint_name, $action) = splice(@coercion_map, 0, 2);
my $type_constraint = ref $constraint_name ? $constraint_name : Moose::Util::TypeConstraints::find_or_parse_type_constraint($constraint_name);
(defined $type_constraint)
- || Moose::throw_error("Could not find the type constraint ($constraint_name) to coerce from");
+ || Moose->throw_error("Could not find the type constraint ($constraint_name) to coerce from");
push @coercions => [
$type_constraint->_compiled_type_constraint,
$action
while (@new_coercion_map) {
my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2);
- Moose::throw_error("A coercion action already exists for '$constraint_name'")
+ Moose->throw_error("A coercion action already exists for '$constraint_name'")
if exists $has_coercion{$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 a Moose::Meta::TypeCoercion::Union for a " .
+ || Moose->throw_error("You can only a Moose::Meta::TypeCoercion::Union for a " .
"Moose::Meta::TypeConstraint::Union, not a $type_constraint");
$self->_compiled_type_coercion(sub {
sub has_coercion_for_type { 0 }
sub add_type_coercions {
- Moose::throw_error("Cannot add additional type coercions to Union types");
+ Moose->throw_error("Cannot add additional type coercions to Union types");
}
1;
return $self;
}
-sub coerce { ((shift)->coercion || Moose::throw_error("Cannot coerce without a type coercion"))->coerce(@_) }
+sub coerce { ((shift)->coercion || Moose->throw_error("Cannot coerce without a type coercion"))->coerce(@_) }
sub check { $_[0]->_compiled_type_constraint->($_[1]) ? 1 : undef }
sub validate {
my ($self, $value) = @_;
my $check = $self->constraint;
(defined $check)
- || Moose::throw_error("Could not compile type constraint '"
+ || Moose->throw_error("Could not compile type constraint '"
. $self->name
. "' because no constraint check");
my $type_constraint = $self->hand_optimized_type_constraint;
- Moose::throw_error("Hand optimized type constraint is not a code reference") unless ref $type_constraint;
+ Moose->throw_error("Hand optimized type constraint is not a code reference") unless ref $type_constraint;
return $type_constraint;
}
my $self = shift;
($self->has_type_parameter)
- || Moose::throw_error("You cannot create a Higher Order type without a type parameter");
+ || Moose->throw_error("You cannot create a Higher Order type without a type parameter");
my $type_parameter = $self->type_parameter;
(blessed $type_parameter && $type_parameter->isa('Moose::Meta::TypeConstraint'))
- || Moose::throw_error("The type parameter must be a Moose meta type");
+ || Moose->throw_error("The type parameter must be a Moose meta type");
foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
if (my $constraint = $type->generate_constraint_for($self)) {
# if we get here, then we couldn't
# find a way to parameterize this type
- Moose::throw_error("The " . $self->name . " constraint cannot be used, because "
+ Moose->throw_error("The " . $self->name . " constraint cannot be used, because "
. $self->parent->name . " doesn't subtype or coerce from a parameterizable type.");
}
use metaclass;
use Scalar::Util 'blessed';
-use Carp 'confess'; # FIXME Moose::throw_error
+use Carp 'confess'; # FIXME Moose->throw_error
our $VERSION = '0.57';
$VERSION = eval $VERSION;
my %args = @_;
my $role = $args{for_class}
- or Moose::throw_error("Cannot call init_meta without specifying a for_class");
+ or Moose->throw_error("Cannot call init_meta without specifying a for_class");
my $metaclass = $args{metaclass} || "Moose::Meta::Role";
if ($role->can('meta')) {
$meta = $role->meta();
(blessed($meta) && $meta->isa('Moose::Meta::Role'))
- || Moose::throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role");
+ || Moose->throw_error("You already have a &meta function, but it does not return a Moose::Meta::Role");
}
else {
$meta = $metaclass->initialize($role);
sub apply_all_roles {
my $applicant = shift;
- Moose::throw_error("Must specify at least one role to apply to $applicant") unless @_;
+ Moose->throw_error("Must specify at least one role to apply to $applicant") unless @_;
my $roles = Data::OptList::mkopt( [@_] );
}
( $_->[0]->can('meta') && $_->[0]->meta->isa('Moose::Meta::Role') )
- || Moose::throw_error("You can only consume roles, "
+ || Moose->throw_error("You can only consume roles, "
. $_->[0]
. " is not a Moose role")
foreach @$roles;
}
(scalar @type_constraint_names >= 2)
- || Moose::throw_error("You must pass in at least 2 type names to make a union");
+ || Moose->throw_error("You must pass in at least 2 type names to make a union");
($REGISTRY->has_type_constraint($_))
- || Moose::throw_error("Could not locate type constraint ($_) for the union")
+ || Moose->throw_error("Could not locate type constraint ($_) for the union")
foreach @type_constraint_names;
return Moose::Meta::TypeConstraint::Union->new(
my ($base_type, $type_parameter) = _parse_parameterized_type_constraint($type_constraint_name);
(defined $base_type && defined $type_parameter)
- || Moose::throw_error("Could not parse type name ($type_constraint_name) correctly");
+ || Moose->throw_error("Could not parse type name ($type_constraint_name) correctly");
($REGISTRY->has_type_constraint($base_type))
- || Moose::throw_error("Could not locate the base type ($base_type)");
+ || Moose->throw_error("Could not locate the base type ($base_type)");
return Moose::Meta::TypeConstraint::Parameterized->new(
name => $type_constraint_name,
# too early for this check
#find_type_constraint("ClassName")->check($class)
- # || Moose::throw_error("Can't create a class type constraint because '$class' is not a class name");
+ # || Moose->throw_error("Can't create a class type constraint because '$class' is not a class name");
my %options = (
class => $class,
# too early for this check
#find_type_constraint("ClassName")->check($class)
- # || Moose::throw_error("Can't create a class type constraint because '$class' is not a class name");
+ # || Moose->throw_error("Can't create a class type constraint because '$class' is not a class name");
my %options = (
role => $role,
sub register_type_constraint ($) {
my $constraint = shift;
- Moose::throw_error("can't register an unnamed type constraint") unless defined $constraint->name;
+ Moose->throw_error("can't register an unnamed type constraint") unless defined $constraint->name;
$REGISTRY->add_type_constraint($constraint);
return $constraint;
}
$type_name = undef;
}
(scalar @values >= 2)
- || Moose::throw_error("You must have at least two values to enumerate through");
+ || Moose->throw_error("You must have at least two values to enumerate through");
my %valid = map { $_ => 1 } @values;
register_type_constraint(
my ($type_name, $coercion_map) = @_;
my $type = find_type_constraint($type_name);
(defined $type)
- || Moose::throw_error("Cannot find type '$type_name', perhaps you forgot to load it.");
+ || Moose->throw_error("Cannot find type '$type_name', perhaps you forgot to load it.");
if ($type->has_coercion) {
$type->coercion->add_type_coercions(@$coercion_map);
}
push @rv => $1;
}
(pos($given) eq length($given))
- || Moose::throw_error("'$given' didn't parse (parse-pos="
+ || Moose->throw_error("'$given' didn't parse (parse-pos="
. pos($given)
. " and str-length="
. length($given)
sub add_parameterizable_type {
my $type = shift;
(blessed $type && $type->isa('Moose::Meta::TypeConstraint::Parameterizable'))
- || Moose::throw_error("Type must be a Moose::Meta::TypeConstraint::Parameterizable not $type");
+ || Moose->throw_error("Type must be a Moose::Meta::TypeConstraint::Parameterizable not $type");
push @PARAMETERIZABLE_TYPES => $type;
}