1 package Moose::Error::Default;
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
11 use Class::MOP::MiniTrait;
13 use base 'Class::MOP::Object';
16 Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
19 my ( $self, @args ) = @_;
20 if(exists $ENV{MOOSE_ERROR_TERSE} && $ENV{MOOSE_ERROR_TERSE}) {
21 $self->create_error_croak( @args );
24 $self->create_error_confess( @args );
28 sub create_error_croak {
29 my ( $self, @args ) = @_;
30 $self->_create_error_carpmess( @args );
33 sub create_error_confess {
34 my ( $self, @args ) = @_;
35 $self->_create_error_carpmess( @args, longmess => 1 );
38 sub _create_error_carpmess {
39 my ( $self, %args ) = @_;
41 my $carp_level = 3 + ( $args{depth} || 1 );
42 local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
44 my @args = exists $args{message} ? $args{message} : ();
46 if ( $args{longmess} || $Carp::Verbose ) {
47 local $Carp::CarpLevel = ( $Carp::CarpLevel || 0 ) + $carp_level;
48 return Carp::longmess(@args);
50 return Carp::ret_summary($carp_level, @args);
62 Moose::Error::Default - L<Carp> based error generation for Moose.
66 This class implements L<Carp> based error generation.
68 The default behavior is like L<Moose::Error::Confess>. To override this
69 to default to L<Moose::Error::Croak>'s behaviour on a system wide basis,
70 set the MOOSE_ERROR_TERSE environment variable to a true value.
78 Create a new error. Delegates to C<create_error_confess> or
79 C<create_error_croak>.
81 =item create_error_confess @args
83 =item create_error_croak @args
85 Creates a new errors string of the specified style.