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 {
# 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)
}
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;