From: Shawn M Moore Date: Thu, 14 Jun 2012 20:55:55 +0000 (-0500) Subject: Simplify the error throwing X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c384420912e5a85dcd94ea3e5746263f649a6d84;p=gitmo%2FMoose.git Simplify the error throwing --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index e21ec2f..657dbbf 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -49,12 +49,7 @@ sub _error_thrower { sub throw_error { my $self = shift; - my $inv = $self->_error_thrower; - unshift @_, "message" if @_ % 2 == 1; - unshift @_, attr => $self if ref $self; - unshift @_, $inv; - my $handler = $inv->can("throw_error"); # to avoid incrementing depth by 1 - goto $handler; + Moose::Util::throw(@_); } sub _inline_throw_error { @@ -64,16 +59,6 @@ sub _inline_throw_error { # XXX ugh $inv = 'Moose::Meta::Class' unless $inv->can('_inline_throw_error'); - # XXX ugh ugh UGH - my $class = $self->associated_class; - if ($class) { - my $class_name = B::perlstring($class->name); - my $attr_name = B::perlstring($self->name); - $args = 'attr => Class::MOP::class_of(' . $class_name . ')' - . '->find_attribute_by_name(' . $attr_name . '), ' - . (defined $args ? $args : ''); - } - return $inv->_inline_throw_error($msg, $args) } diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index e6c5875..b0152ee 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -765,82 +765,17 @@ our $error_level; sub throw_error { my ( $self, @args ) = @_; - local $error_level = ($error_level || 0) + 1; - $self->raise_error($self->create_error(@args)); -} - -sub _inline_throw_error { - my ( $self, @args ) = @_; - $self->_inline_raise_error($self->_inline_create_error(@args)); -} - -sub raise_error { - my ( $self, @args ) = @_; - die @args; -} - -sub _inline_raise_error { - my ( $self, $error ) = @_; - - return 'die ' . $error; -} - -sub create_error { - my ( $self, @args ) = @_; - - require Carp::Heavy; - - local $error_level = ($error_level || 0 ) + 1; - if ( @args % 2 == 1 ) { - unshift @args, "message"; - } - - my %args = ( metaclass => $self, last_error => $@, @args ); - - $args{depth} += $error_level; - - my $class = ref $self ? $self->error_class : "Moose::Error::Default"; - - load_class($class); - - $class->new( - Carp::caller_info($args{depth}), - %args - ); + Moose::Util::throw(@args); } -sub _inline_create_error { +sub _inline_throw_error { my ( $self, $msg, $args ) = @_; - # XXX ignore $args for now, nothing currently uses it anyway - require Carp::Heavy; - - my %args = ( - metaclass => $self, - last_error => $@, - message => $msg, - ); - - my $class = ref $self ? $self->error_class : "Moose::Error::Default"; - - load_class($class); - - # don't check inheritance here - the intention is that the class needs - # to provide a non-inherited inlining method, because falling back to - # the default inlining method is most likely going to be wrong - # yes, this is a huge hack, but so is the entire error system, so. - return - '$meta->create_error(' - . $msg - . ( defined $args ? ', ' . $args : q{} ) . ');' - unless $class->meta->has_method('_inline_new'); - - $class->_inline_new( - # XXX ignore this for now too - # Carp::caller_info($args{depth}), - %args - ); + return 'Moose::Util::throw(' . + 'message => ' . $msg . + ($args ? (', ' . $args) : '') + . ');'; } 1;