1 package Moose::Error::Default;
7 use Class::MOP::MiniTrait;
9 use Moose::Error::Util;
11 use base 'Class::MOP::Object';
13 Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
16 my ( $self, @args ) = @_;
17 # can't use Moose::Error::Util::create_error here because that would break
18 # inheritance. we don't care about that for the inlined version, because
19 # the inlined versions are explicitly not inherited.
20 if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
21 $self->create_error_croak( @args );
24 $self->create_error_confess( @args );
29 my ( $self, %args ) = @_;
31 my $depth = ($args{depth} || 0) - 1;
32 return 'Moose::Error::Util::create_error('
33 . 'message => ' . $args{message} . ', '
34 . 'depth => ' . $depth . ', '
38 sub create_error_croak {
39 my ( $self, @args ) = @_;
40 return Moose::Error::Util::create_error_croak(@args);
43 sub create_error_confess {
44 my ( $self, @args ) = @_;
45 return Moose::Error::Util::create_error_confess(@args);
50 # ABSTRACT: L<Carp> based error generation for Moose.
58 This class implements L<Carp> based error generation.
60 The default behavior is like L<Moose::Error::Confess>. To override this to
61 default to L<Moose::Error::Croak>'s behaviour on a system wide basis, set the
62 MOOSE_ERROR_STYLE environment variable to C<croak>. The use of this
63 environment variable is considered experimental, and may change in a future
70 =item B<< Moose::Error::Default->new(@args) >>
72 Create a new error. Delegates to C<create_error_confess> or
73 C<create_error_croak>.
75 =item B<< $error->create_error_confess(@args) >>
77 =item B<< $error->create_error_croak(@args) >>
79 Creates a new errors string of the specified style.