From: Yuval Kogman Date: Thu, 4 Sep 2008 02:00:59 +0000 (+0000) Subject: Moose::throw_error -> Moose->throw_error X-Git-Tag: 0.58~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c245d69b0b9984226cc876c0578b18e89b5cbf23;p=gitmo%2FMoose.git Moose::throw_error -> Moose->throw_error --- diff --git a/lib/Moose.pm b/lib/Moose.pm index cd4db7b..c54d8db 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -36,7 +36,11 @@ use Moose::Meta::Role::Application::ToInstance; 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; @@ -153,12 +157,11 @@ sub init_meta { 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 @@ -169,7 +172,7 @@ sub init_meta { 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 @@ -211,7 +214,7 @@ sub init_meta { 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; } diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index 17ca000..bb5071c 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -230,7 +230,7 @@ sub _make_sub_exporter_params { _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; @@ -260,7 +260,7 @@ sub _apply_meta_traits { 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 ); diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 37149cc..b7b38f5 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -59,7 +59,7 @@ sub associated_metaclass { (shift)->{'associated_metaclass'} } # 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; diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 376f7bc..d872f79 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -214,7 +214,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->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; } @@ -259,7 +259,7 @@ __PACKAGE__->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->throw_error("Roles must be instances of Moose::Meta::Role"); push @{$self->get_roles} => $role; $self->reset_package_cache_flag; } @@ -277,7 +277,7 @@ sub calculate_all_roles { 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 @@ -374,7 +374,7 @@ sub wrap_method_body { 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, @@ -385,7 +385,7 @@ sub wrap_method_body { 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)) { @@ -429,11 +429,11 @@ sub get_method_list { 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 }, @@ -449,7 +449,7 @@ sub apply { 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; diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index cc570ae..c07d000 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -71,7 +71,7 @@ sub check_role_exclusions { 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); } } @@ -118,7 +118,7 @@ sub apply_attributes { 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}; } @@ -188,12 +188,12 @@ sub apply_override_method_modifiers { 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}; diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 46ff629..0a9e3b6 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -20,10 +20,10 @@ sub apply { 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); } @@ -51,7 +51,7 @@ sub apply_attributes { 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 { @@ -75,7 +75,7 @@ sub apply_methods { 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( @@ -119,7 +119,7 @@ sub apply_override_method_modifiers { # 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."); } @@ -129,7 +129,7 @@ sub apply_override_method_modifiers { # 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."); } diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 92b47a5..bdfc8ba 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -34,7 +34,7 @@ sub new { 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 @@ -50,7 +50,7 @@ sub new { 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 diff --git a/lib/Moose/Meta/TypeCoercion.pm b/lib/Moose/Meta/TypeCoercion.pm index ecaff54..f9d1e06 100644 --- a/lib/Moose/Meta/TypeCoercion.pm +++ b/lib/Moose/Meta/TypeCoercion.pm @@ -44,7 +44,7 @@ sub compile_type_coercion { 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 @@ -78,7 +78,7 @@ sub add_type_coercions { 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); diff --git a/lib/Moose/Meta/TypeCoercion/Union.pm b/lib/Moose/Meta/TypeCoercion/Union.pm index 1563483..1eef306 100644 --- a/lib/Moose/Meta/TypeCoercion/Union.pm +++ b/lib/Moose/Meta/TypeCoercion/Union.pm @@ -18,7 +18,7 @@ sub compile_type_coercion { 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 { @@ -43,7 +43,7 @@ sub compile_type_coercion { 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; diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index 686183a..cf57851 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -65,7 +65,7 @@ sub new { 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) = @_; @@ -154,7 +154,7 @@ sub _actually_compile_type_constraint { 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"); @@ -169,7 +169,7 @@ sub _compile_hand_optimized_type_constraint { 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; } diff --git a/lib/Moose/Meta/TypeConstraint/Parameterized.pm b/lib/Moose/Meta/TypeConstraint/Parameterized.pm index 5460166..3d7cbae 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterized.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -36,12 +36,12 @@ sub compile_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)) { @@ -52,7 +52,7 @@ sub compile_type_constraint { # 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."); } diff --git a/lib/Moose/Meta/TypeConstraint/Registry.pm b/lib/Moose/Meta/TypeConstraint/Registry.pm index 466fe1b..d959632 100644 --- a/lib/Moose/Meta/TypeConstraint/Registry.pm +++ b/lib/Moose/Meta/TypeConstraint/Registry.pm @@ -6,7 +6,7 @@ use warnings; 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; diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 02f0591..4eedae3 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -123,7 +123,7 @@ sub init_meta { 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"; @@ -135,7 +135,7 @@ sub init_meta { 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); diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index a428d2d..ad87688 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -72,7 +72,7 @@ sub search_class_by_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( [@_] ); @@ -83,7 +83,7 @@ sub apply_all_roles { } ( $_->[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; diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 7aa6f99..582c1c9 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -103,10 +103,10 @@ sub create_type_constraint_union (@) { } (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( @@ -124,10 +124,10 @@ sub create_parameterized_type_constraint ($) { 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, @@ -142,7 +142,7 @@ sub create_class_type_constraint ($;$) { # 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, @@ -160,7 +160,7 @@ sub create_role_type_constraint ($;$) { # 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, @@ -247,7 +247,7 @@ sub find_type_constraint ($) { 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; } @@ -315,7 +315,7 @@ sub enum ($;@) { $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( @@ -405,7 +405,7 @@ sub _install_type_coercions ($$) { 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); } @@ -464,7 +464,7 @@ sub _install_type_coercions ($$) { 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) @@ -616,7 +616,7 @@ sub get_all_parameterizable_types { @PARAMETERIZABLE_TYPES } 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; }