Require Dist::Zilla 4.200016+
[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;
68567b15 7use Class::MOP::MiniTrait;
41daa828 8
8748a8e8 9use Moose::Error::Util;
10
4f5ca7c5 11use base 'Class::MOP::Object';
12
68567b15 13Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');
41daa828 14
bf6fa6b3 15sub new {
16 my ( $self, @args ) = @_;
8748a8e8 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.
692a93f6 20 if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
aeef093c 21 $self->create_error_croak( @args );
22 }
23 else {
24 $self->create_error_confess( @args );
25 }
bf6fa6b3 26}
27
bcc04ae1 28sub _inline_new {
72c4fdf1 29 my ( $self, %args ) = @_;
bcc04ae1 30
72c4fdf1 31 my $depth = ($args{depth} || 0) - 1;
8748a8e8 32 return 'Moose::Error::Util::create_error('
72c4fdf1 33 . 'message => ' . $args{message} . ', '
34 . 'depth => ' . $depth . ', '
35 . ')';
bcc04ae1 36}
37
bf6fa6b3 38sub create_error_croak {
39 my ( $self, @args ) = @_;
8748a8e8 40 return Moose::Error::Util::create_error_croak(@args);
bf6fa6b3 41}
42
43sub create_error_confess {
44 my ( $self, @args ) = @_;
8748a8e8 45 return Moose::Error::Util::create_error_confess(@args);
bf6fa6b3 46}
47
9c1bf11e 481;
bf6fa6b3 49
ad46f524 50# ABSTRACT: L<Carp> based error generation for Moose.
51
bf6fa6b3 52__END__
53
54=pod
55
bf6fa6b3 56=head1 DESCRIPTION
57
58This class implements L<Carp> based error generation.
59
1b27b2a6 60The default behavior is like L<Moose::Error::Confess>. To override this to
61default to L<Moose::Error::Croak>'s behaviour on a system wide basis, set the
62MOOSE_ERROR_STYLE environment variable to C<croak>. The use of this
63environment variable is considered experimental, and may change in a future
64release.
bf6fa6b3 65
66=head1 METHODS
67
68=over 4
69
ad3882b5 70=item B<< Moose::Error::Default->new(@args) >>
bf6fa6b3 71
cef1e197 72Create a new error. Delegates to C<create_error_confess> or
73C<create_error_croak>.
bf6fa6b3 74
ad3882b5 75=item B<< $error->create_error_confess(@args) >>
bf6fa6b3 76
ad3882b5 77=item B<< $error->create_error_croak(@args) >>
bf6fa6b3 78
79Creates a new errors string of the specified style.
80
81=back
82
83=cut
84
85