my ( $self, %args ) = @_;
my $depth = ($args{depth} || 0) - 1;
- return $self . '->new('
+ return 'Moose::Error::Util::create_error_confess('
. 'message => ' . $args{message} . ', '
. 'depth => ' . $depth . ', '
. ')';
my ( $self, %args ) = @_;
my $depth = ($args{depth} || 0) - 1;
- return $self . '->new('
+ return 'Moose::Error::Util::create_error_croak('
. 'message => ' . $args{message} . ', '
. 'depth => ' . $depth . ', '
. ')';
use Carp::Heavy;
use Class::MOP::MiniTrait;
+use Moose::Error::Util;
+
use base 'Class::MOP::Object';
Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
sub new {
my ( $self, @args ) = @_;
+ # can't use Moose::Error::Util::create_error here because that would break
+ # inheritance. we don't care about that for the inlined version, because
+ # the inlined versions are explicitly not inherited.
if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
$self->create_error_croak( @args );
}
my ( $self, %args ) = @_;
my $depth = ($args{depth} || 0) - 1;
- return $self . '->new('
+ return 'Moose::Error::Util::create_error('
. 'message => ' . $args{message} . ', '
. 'depth => ' . $depth . ', '
. ')';
sub create_error_croak {
my ( $self, @args ) = @_;
- $self->_create_error_carpmess( @args );
+ return Moose::Error::Util::create_error_croak(@args);
}
sub create_error_confess {
my ( $self, @args ) = @_;
- $self->_create_error_carpmess( @args, longmess => 1 );
-}
-
-sub _create_error_carpmess {
- my ( $self, %args ) = @_;
-
- my $carp_level = 4 + ( $args{depth} || 0 );
- local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
-
- my @args = exists $args{message} ? $args{message} : ();
-
- if ( $args{longmess} || $Carp::Verbose ) {
- local $Carp::CarpLevel = ( $Carp::CarpLevel || 0 ) + $carp_level;
- return Carp::longmess(@args);
- } else {
- return Carp::ret_summary($carp_level, @args);
- }
+ return Moose::Error::Util::create_error_confess(@args);
}
1;
--- /dev/null
+package # pretend this doesn't exist, because it shouldn't
+ Moose::Error::Util;
+
+use strict;
+use warnings;
+
+# this intentionally exists to have a place to put this logic that doesn't
+# involve loading Class::MOP, so... don't do that
+
+use Carp::Heavy;
+
+sub _create_error_carpmess {
+ my %args = @_;
+
+ my $carp_level = 3 + ( $args{depth} || 0 );
+ local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
+
+ my @args = exists $args{message} ? $args{message} : ();
+
+ if ( $args{longmess} || $Carp::Verbose ) {
+ local $Carp::CarpLevel = ( $Carp::CarpLevel || 0 ) + $carp_level;
+ return Carp::longmess(@args);
+ } else {
+ return Carp::ret_summary($carp_level, @args);
+ }
+}
+
+sub create_error_croak {
+ _create_error_carpmess(@_);
+}
+
+sub create_error_confess {
+ _create_error_carpmess(@_, longmess => 1);
+}
+
+sub create_error {
+ if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
+ create_error_croak(@_);
+ }
+ else {
+ create_error_confess(@_);
+ }
+}
+
+1;