this test should be for definedness
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
index e554951..a5c44de 100644 (file)
@@ -3,16 +3,26 @@ package Moose::Error::Default;
 use strict;
 use warnings;
 
-our $VERSION   = '1.12';
+our $VERSION   = '1.15';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Carp::Heavy;
+use Class::MOP::MiniTrait;
 
+use base 'Class::MOP::Object';
+
+
+Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
 
 sub new {
     my ( $self, @args ) = @_;
-    $self->create_error_confess( @args );
+    if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
+        $self->create_error_croak( @args );
+    }
+    else {
+        $self->create_error_confess( @args );
+    }
 }
 
 sub create_error_croak {
@@ -55,7 +65,9 @@ Moose::Error::Default - L<Carp> based error generation for Moose.
 
 This class implements L<Carp> based error generation.
 
-The default behavior is like L<Moose::Error::Confess>.
+The default behavior is like L<Moose::Error::Confess>. To override this
+to default to L<Moose::Error::Croak>'s behaviour on a system wide basis,
+set the MOOSE_ERROR_STYLE environment variable to C<croak>.
 
 =head1 METHODS
 
@@ -63,7 +75,8 @@ The default behavior is like L<Moose::Error::Confess>.
 
 =item new @args
 
-Create a new error. Delegates to C<create_error_confess>.
+Create a new error. Delegates to C<create_error_confess> or
+C<create_error_croak>.
 
 =item create_error_confess @args