Remove Moose::Meta::Object::Trait
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
CommitLineData
bf6fa6b3 1package Moose::Error::Default;
2
c0e91e5f 3use strict;
4use warnings;
5
41daa828 6use Carp::Heavy;
7
8748a8e8 8use Moose::Error::Util;
9
4f5ca7c5 10use base 'Class::MOP::Object';
11
bf6fa6b3 12sub new {
13 my ( $self, @args ) = @_;
8748a8e8 14 # can't use Moose::Error::Util::create_error here because that would break
15 # inheritance. we don't care about that for the inlined version, because
16 # the inlined versions are explicitly not inherited.
692a93f6 17 if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
aeef093c 18 $self->create_error_croak( @args );
19 }
20 else {
21 $self->create_error_confess( @args );
22 }
bf6fa6b3 23}
24
bcc04ae1 25sub _inline_new {
72c4fdf1 26 my ( $self, %args ) = @_;
bcc04ae1 27
72c4fdf1 28 my $depth = ($args{depth} || 0) - 1;
8748a8e8 29 return 'Moose::Error::Util::create_error('
72c4fdf1 30 . 'message => ' . $args{message} . ', '
31 . 'depth => ' . $depth . ', '
32 . ')';
bcc04ae1 33}
34
bf6fa6b3 35sub create_error_croak {
36 my ( $self, @args ) = @_;
8748a8e8 37 return Moose::Error::Util::create_error_croak(@args);
bf6fa6b3 38}
39
40sub create_error_confess {
41 my ( $self, @args ) = @_;
8748a8e8 42 return Moose::Error::Util::create_error_confess(@args);
bf6fa6b3 43}
44
9c1bf11e 451;
bf6fa6b3 46
ad46f524 47# ABSTRACT: L<Carp> based error generation for Moose.
48
bf6fa6b3 49__END__
50
51=pod
52
bf6fa6b3 53=head1 DESCRIPTION
54
55This class implements L<Carp> based error generation.
56
1b27b2a6 57The default behavior is like L<Moose::Error::Confess>. To override this to
58default to L<Moose::Error::Croak>'s behaviour on a system wide basis, set the
59MOOSE_ERROR_STYLE environment variable to C<croak>. The use of this
60environment variable is considered experimental, and may change in a future
61release.
bf6fa6b3 62
63=head1 METHODS
64
65=over 4
66
ad3882b5 67=item B<< Moose::Error::Default->new(@args) >>
bf6fa6b3 68
cef1e197 69Create a new error. Delegates to C<create_error_confess> or
70C<create_error_croak>.
bf6fa6b3 71
ad3882b5 72=item B<< $error->create_error_confess(@args) >>
bf6fa6b3 73
ad3882b5 74=item B<< $error->create_error_croak(@args) >>
bf6fa6b3 75
76Creates a new errors string of the specified style.
77
78=back
79
80=cut
81
82