Commit | Line | Data |
bf6fa6b3 |
1 | package Moose::Error::Default; |
2 | |
c0e91e5f |
3 | use strict; |
4 | use warnings; |
5 | |
41daa828 |
6 | use Carp::Heavy; |
68567b15 |
7 | use Class::MOP::MiniTrait; |
41daa828 |
8 | |
8748a8e8 |
9 | use Moose::Error::Util; |
10 | |
4f5ca7c5 |
11 | use base 'Class::MOP::Object'; |
12 | |
68567b15 |
13 | Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); |
41daa828 |
14 | |
bf6fa6b3 |
15 | sub 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 |
28 | sub _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 |
38 | sub create_error_croak { |
39 | my ( $self, @args ) = @_; |
8748a8e8 |
40 | return Moose::Error::Util::create_error_croak(@args); |
bf6fa6b3 |
41 | } |
42 | |
43 | sub create_error_confess { |
44 | my ( $self, @args ) = @_; |
8748a8e8 |
45 | return Moose::Error::Util::create_error_confess(@args); |
bf6fa6b3 |
46 | } |
47 | |
9c1bf11e |
48 | 1; |
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 | |
58 | This class implements L<Carp> based error generation. |
59 | |
1b27b2a6 |
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 |
64 | release. |
bf6fa6b3 |
65 | |
66 | =head1 METHODS |
67 | |
68 | =over 4 |
69 | |
ad3882b5 |
70 | =item B<< Moose::Error::Default->new(@args) >> |
bf6fa6b3 |
71 | |
cef1e197 |
72 | Create a new error. Delegates to C<create_error_confess> or |
73 | C<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 | |
79 | Creates a new errors string of the specified style. |
80 | |
81 | =back |
82 | |
83 | =cut |
84 | |
85 | |