From: Yuval Kogman Date: Thu, 4 Sep 2008 01:34:34 +0000 (+0000) Subject: Merge ../Moose-error into pluggable_errors X-Git-Tag: 0.58~54^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c0b35998743adde444d886607da524c7094327c;p=gitmo%2FMoose.git Merge ../Moose-error into pluggable_errors --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 69dbc63..e32844b 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -36,6 +36,8 @@ use Moose::Meta::Role::Application::ToInstance; use Moose::Util::TypeConstraints; use Moose::Util (); +BEGIN { *throw_error = \&confess } # FIXME make this smarter + sub extends { my $class = shift; @@ -151,11 +153,11 @@ sub init_meta { my %args = @_; my $class = $args{for_class} - or confess "Cannot call init_meta without specifying a for_class"; + or 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'; - confess + throw_error "The Metaclass $metaclass must be a subclass of Moose::Meta::Class." unless $metaclass->isa('Moose::Meta::Class'); @@ -167,7 +169,7 @@ sub init_meta { if ( $meta = Class::MOP::get_metaclass_by_name($class) ) { unless ( $meta->isa("Moose::Meta::Class") ) { - confess "$class already has a metaclass, but it does not inherit $metaclass ($meta)"; + throw_error "$class already has a metaclass, but it does not inherit $metaclass ($meta)"; } } else { # no metaclass, no 'meta' method @@ -209,7 +211,7 @@ sub init_meta { my $method_meta = $class->meta; ( blessed($method_meta) && $method_meta->isa('Moose::Meta::Class') ) - || confess "$class already has a &meta function, but it does not return a Moose::Meta::Class ($meta)"; + || throw_error "$class already has a &meta function, but it does not return a Moose::Meta::Class ($meta)"; $meta = $method_meta; } @@ -843,6 +845,10 @@ instead, which lets you stack multiple C-alike modules sanely. It handles getting the exported functions into the right place for you. +=head2 throw_error + +An alias for C, used by internally by Moose. + =head1 CAVEATS =over 4 diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index b09de9e..17ca000 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -3,7 +3,6 @@ package Moose::Exporter; use strict; use warnings; -use Carp qw( confess ); use Class::MOP; use List::MoreUtils qw( first_index uniq ); use Moose::Util::MetaRole; @@ -231,8 +230,7 @@ sub _make_sub_exporter_params { _apply_meta_traits( $CALLER, $traits ); } elsif ( @{$traits} ) { - confess - "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; @@ -262,9 +260,9 @@ sub _apply_meta_traits { my $meta = $class->meta(); my $type = ( split /::/, ref $meta )[-1] - or confess + or Moose::throw_error( 'Cannot determine metaclass type for trait application . Meta isa ' - . ref $meta; + . ref $meta ); my @resolved_traits = map { Moose::Util::resolve_metatrait_alias( $type => $_ ) } diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 8fdf3a7..37149cc 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 { Carp::confess "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 13034ce..376f7bc 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -5,7 +5,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; @@ -215,8 +214,8 @@ $META->add_attribute('override_method_modifiers' => ( sub add_override_method_modifier { my ($self, $method_name, $method) = @_; (!$self->has_method($method_name)) - || confess "Cannot add an override of method '$method_name' " . - "because there is a local version of '$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; } @@ -260,7 +259,7 @@ __PACKAGE__->meta->add_attribute('roles' => ( sub add_role { my ($self, $role) = @_; (blessed($role) && $role->isa('Moose::Meta::Role')) - || confess "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; } @@ -278,7 +277,7 @@ sub calculate_all_roles { sub does_role { my ($self, $role_name) = @_; (defined $role_name) - || confess "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 @@ -375,7 +374,7 @@ sub wrap_method_body { my $body = delete $args{body}; # delete is for compat ('CODE' eq ref($body)) - || confess "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, @@ -386,7 +385,7 @@ sub wrap_method_body { sub add_method { my ($self, $method_name, $method) = @_; (defined $method_name && $method_name) - || confess "You must define a method name"; + || Moose::throw_error("You must define a method name"); my $body; if (blessed($method)) { @@ -430,11 +429,11 @@ sub get_method_list { sub alias_method { my ($self, $method_name, $method) = @_; (defined $method_name && $method_name) - || confess "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)) - || confess "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 }, @@ -450,7 +449,7 @@ sub apply { my ($self, $other, @args) = @_; (blessed($other)) - || confess "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 7886a81..cc570ae 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -4,7 +4,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; use Moose::Meta::Role::Composite; @@ -72,7 +71,7 @@ sub check_role_exclusions { foreach my $role (@{$c->get_roles}) { foreach my $excluded (@all_excluded_roles) { - confess "Conflict detected: " . $role->name . " excludes role '" . $excluded . "'" + Moose::throw_error("Conflict detected: " . $role->name . " excludes role '" . $excluded . "'") if $role->does_role($excluded); } } @@ -119,8 +118,8 @@ sub apply_attributes { my %seen; foreach my $attr (@all_attributes) { if (exists $seen{$attr->{name}}) { - confess "We have encountered an attribute conflict with '" . $attr->{name} . "' " - . "during composition. This is fatal error and cannot be disambiguated." + 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}; } $seen{$attr->{name}} = $attr->{attr}; @@ -189,14 +188,14 @@ sub apply_override_method_modifiers { my %seen; foreach my $override (@all_overrides) { - confess "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." + "is fatal error." ) if $c->has_method($override->{name}); if (exists $seen{$override->{name}}) { - confess "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." + "This is fatal error.") if $seen{$override->{name}} != $override->{method}; } $seen{$override->{name}} = $override->{method}; diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index 32b6fb2..8342bea 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -4,7 +4,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; @@ -22,11 +21,11 @@ sub apply { sub check_role_exclusions { my ($self, $role, $class) = @_; if ($class->excludes_role($role->name)) { - confess "Conflict detected: " . $class->name . " excludes role '" . $role->name . "'"; + $class->throw_error("Conflict detected: " . $class->name . " excludes role '" . $role->name . "'"); } foreach my $excluded_role_name ($role->get_excluded_roles_list) { if ($class->does_role($excluded_role_name)) { - confess "The class " . $class->name . " does the excluded role '$excluded_role_name'"; + $class->throw_error("The class " . $class->name . " does the excluded role '$excluded_role_name'"); } } } @@ -45,8 +44,8 @@ sub check_required_methods { next if $self->is_aliased_method($required_method_name); - confess "'" . $role->name . "' requires the method '$required_method_name' " . - "to be implemented by '" . $class->name . "'"; + $class->throw_error("'" . $role->name . "' requires the method '$required_method_name' " . + "to be implemented by '" . $class->name . "'"); } else { # NOTE: @@ -57,8 +56,8 @@ sub check_required_methods { # check if it is a generated accessor ... (!$method->isa('Class::MOP::Method::Accessor')) - || confess "'" . $role->name . "' requires the method '$required_method_name' " . - "to be implemented by '" . $class->name . "', the method is only an attribute accessor"; + || $class->throw_error("'" . $role->name . "' requires the method '$required_method_name' " . + "to be implemented by '" . $class->name . "', the method is only an attribute accessor"); # NOTE: # All other tests here have been removed, they were tests @@ -123,7 +122,7 @@ sub apply_methods { if ($class->has_method($aliased_method_name) && # and if they are not the same thing ... $class->get_method($aliased_method_name)->body != $role->get_method($method_name)->body) { - confess "Cannot create a method alias if a local method of the same name exists"; + $class->throw_error("Cannot create a method alias if a local method of the same name exists"); } $class->alias_method( $aliased_method_name, diff --git a/lib/Moose/Meta/Role/Application/ToInstance.pm b/lib/Moose/Meta/Role/Application/ToInstance.pm index 7513ceb..14f5d87 100644 --- a/lib/Moose/Meta/Role/Application/ToInstance.pm +++ b/lib/Moose/Meta/Role/Application/ToInstance.pm @@ -4,7 +4,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; diff --git a/lib/Moose/Meta/Role/Application/ToRole.pm b/lib/Moose/Meta/Role/Application/ToRole.pm index 29a7eb7..46ff629 100644 --- a/lib/Moose/Meta/Role/Application/ToRole.pm +++ b/lib/Moose/Meta/Role/Application/ToRole.pm @@ -4,7 +4,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; @@ -21,10 +20,10 @@ sub apply { sub check_role_exclusions { my ($self, $role1, $role2) = @_; - confess "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) { - confess "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); } @@ -52,8 +51,8 @@ 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)) { - confess "Role '" . $role1->name . "' has encountered an attribute conflict " . - "during composition. This is fatal error and cannot be disambiguated."; + Moose::throw_error("Role '" . $role1->name . "' has encountered an attribute conflict " . + "during composition. This is fatal error and cannot be disambiguated."); } else { $role2->add_attribute( @@ -76,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) { - confess "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( @@ -120,9 +119,9 @@ sub apply_override_method_modifiers { # we have a conflict here, because you cannot # combine an overriden method with a locally # defined one - confess "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."; + "is fatal error."); } else { # if we are a role, we need to make sure @@ -130,9 +129,9 @@ 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)) { - confess "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."; + "This is fatal error."); } else { # if there is no conflict, diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 5900480..92b47a5 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -4,7 +4,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; @@ -35,7 +34,7 @@ sub new { my ($class, %params) = @_; # the roles param is required ... ($_->isa('Moose::Meta::Role')) - || confess "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 @@ -51,7 +50,7 @@ sub new { sub alias_method { my ($self, $method_name, $method) = @_; (defined $method_name && $method_name) - || confess "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 3f0618b..ecaff54 100644 --- a/lib/Moose/Meta/TypeCoercion.pm +++ b/lib/Moose/Meta/TypeCoercion.pm @@ -5,8 +5,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; - use Moose::Meta::Attribute; use Moose::Util::TypeConstraints (); @@ -46,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) - || confess "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 @@ -80,7 +78,7 @@ sub add_type_coercions { while (@new_coercion_map) { my ($constraint_name, $action) = splice(@new_coercion_map, 0, 2); - confess "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 6291347..1563483 100644 --- a/lib/Moose/Meta/TypeCoercion/Union.pm +++ b/lib/Moose/Meta/TypeCoercion/Union.pm @@ -5,7 +5,6 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; use Scalar::Util 'blessed'; our $VERSION = '0.57'; @@ -19,8 +18,8 @@ sub compile_type_coercion { my $type_constraint = $self->type_constraint; (blessed $type_constraint && $type_constraint->isa('Moose::Meta::TypeConstraint::Union')) - || confess "You can only a Moose::Meta::TypeCoercion::Union for a " . - "Moose::Meta::TypeConstraint::Union, not a $type_constraint"; + || 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 { my $value = shift; @@ -44,7 +43,7 @@ sub compile_type_coercion { sub has_coercion_for_type { 0 } sub add_type_coercions { - confess "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 d527edd..686183a 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -8,7 +8,6 @@ use metaclass; use overload '""' => sub { shift->name }, # stringify to tc name fallback => 1; -use Carp 'confess'; use Scalar::Util qw(blessed refaddr); use base qw(Class::MOP::Object); @@ -66,7 +65,7 @@ sub new { return $self; } -sub coerce { ((shift)->coercion || confess "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) = @_; @@ -155,9 +154,9 @@ sub _actually_compile_type_constraint { my $check = $self->constraint; (defined $check) - || confess "Could not compile type constraint '" + || Moose::throw_error("Could not compile type constraint '" . $self->name - . "' because no constraint check"; + . "' because no constraint check"); return $self->_compile_subtype($check) if $self->has_parent; @@ -170,7 +169,7 @@ sub _compile_hand_optimized_type_constraint { my $type_constraint = $self->hand_optimized_type_constraint; - confess 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 7ece248..5460166 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterized.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -5,7 +5,6 @@ use warnings; use metaclass; use Scalar::Util 'blessed'; -use Carp 'confess'; use Moose::Util::TypeConstraints; our $VERSION = '0.57'; @@ -37,12 +36,12 @@ sub compile_type_constraint { my $self = shift; ($self->has_type_parameter) - || confess "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')) - || confess "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)) { @@ -53,8 +52,8 @@ sub compile_type_constraint { # if we get here, then we couldn't # find a way to parameterize this type - confess "The " . $self->name . " constraint cannot be used, because " - . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."; + Moose::throw_error("The " . $self->name . " constraint cannot be used, because " + . $self->parent->name . " doesn't subtype or coerce from a parameterizable type."); } 1; diff --git a/lib/Moose/Meta/TypeConstraint/Registry.pm b/lib/Moose/Meta/TypeConstraint/Registry.pm index 19784e9..466fe1b 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'; +use Carp 'confess'; # FIXME Moose::throw_error our $VERSION = '0.57'; $VERSION = eval $VERSION; diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 8a1517c..a428d2d 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -5,7 +5,6 @@ use warnings; use Sub::Exporter; use Scalar::Util 'blessed'; -use Carp 'confess'; use Class::MOP 0.57; our $VERSION = '0.57'; @@ -73,7 +72,7 @@ sub search_class_by_role { sub apply_all_roles { my $applicant = shift; - confess "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( [@_] ); @@ -84,9 +83,9 @@ sub apply_all_roles { } ( $_->[0]->can('meta') && $_->[0]->meta->isa('Moose::Meta::Role') ) - || confess "You can only consume roles, " + || Moose::throw_error("You can only consume roles, " . $_->[0] - . " is not a Moose role" + . " is not a Moose role") foreach @$roles; if ( scalar @$roles == 1 ) { diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 5bb95c2..7aa6f99 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -81,18 +81,6 @@ Moose::Exporter->setup_import_methods( my $REGISTRY = Moose::Meta::TypeConstraint::Registry->new; -sub confess { - my ($msg, @args) = @_; - - my $caller = caller(2); - if ( $caller->can("meta") and my $throw = $caller->meta->can("throw_error") ) { - goto $throw; - } else { - @_ = $msg; - goto &Carp::confess; - } -} - sub get_type_constraint_registry { $REGISTRY } sub list_all_type_constraints { keys %{$REGISTRY->type_constraints} } sub export_type_constraints_as_functions { @@ -115,10 +103,10 @@ sub create_type_constraint_union (@) { } (scalar @type_constraint_names >= 2) - || confess "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($_)) - || confess "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( @@ -136,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) - || confess "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)) - || confess "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, @@ -154,7 +142,7 @@ sub create_class_type_constraint ($;$) { # too early for this check #find_type_constraint("ClassName")->check($class) - # || confess "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, @@ -172,7 +160,7 @@ sub create_role_type_constraint ($;$) { # too early for this check #find_type_constraint("ClassName")->check($class) - # || confess "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, @@ -259,7 +247,7 @@ sub find_type_constraint ($) { sub register_type_constraint ($) { my $constraint = shift; - confess "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; } @@ -327,7 +315,7 @@ sub enum ($;@) { $type_name = undef; } (scalar @values >= 2) - || confess "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( @@ -417,7 +405,7 @@ sub _install_type_coercions ($$) { my ($type_name, $coercion_map) = @_; my $type = find_type_constraint($type_name); (defined $type) - || confess "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); } @@ -476,11 +464,11 @@ sub _install_type_coercions ($$) { push @rv => $1; } (pos($given) eq length($given)) - || confess "'$given' didn't parse (parse-pos=" + || Moose::throw_error("'$given' didn't parse (parse-pos=" . pos($given) . " and str-length=" . length($given) - . ")"; + . ")"); @rv; } @@ -628,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')) - || confess "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; }