Commit | Line | Data |
bf6fa6b3 |
1 | package Moose::Error::Default; |
2 | |
c0e91e5f |
3 | use strict; |
4 | use warnings; |
5 | |
41daa828 |
6 | use Carp::Heavy; |
7 | |
8748a8e8 |
8 | use Moose::Error::Util; |
9 | |
4f5ca7c5 |
10 | use base 'Class::MOP::Object'; |
11 | |
bf6fa6b3 |
12 | sub 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 |
25 | sub _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 |
35 | sub create_error_croak { |
36 | my ( $self, @args ) = @_; |
8748a8e8 |
37 | return Moose::Error::Util::create_error_croak(@args); |
bf6fa6b3 |
38 | } |
39 | |
40 | sub create_error_confess { |
41 | my ( $self, @args ) = @_; |
8748a8e8 |
42 | return Moose::Error::Util::create_error_confess(@args); |
bf6fa6b3 |
43 | } |
44 | |
9c1bf11e |
45 | 1; |
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 | |
55 | This class implements L<Carp> based error generation. |
56 | |
1b27b2a6 |
57 | The default behavior is like L<Moose::Error::Confess>. To override this to |
58 | default to L<Moose::Error::Croak>'s behaviour on a system wide basis, set the |
59 | MOOSE_ERROR_STYLE environment variable to C<croak>. The use of this |
60 | environment variable is considered experimental, and may change in a future |
61 | release. |
bf6fa6b3 |
62 | |
63 | =head1 METHODS |
64 | |
65 | =over 4 |
66 | |
ad3882b5 |
67 | =item B<< Moose::Error::Default->new(@args) >> |
bf6fa6b3 |
68 | |
cef1e197 |
69 | Create a new error. Delegates to C<create_error_confess> or |
70 | C<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 | |
76 | Creates a new errors string of the specified style. |
77 | |
78 | =back |
79 | |
80 | =cut |
81 | |
82 | |