Remove Moose::Meta::Object::Trait
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
1 package Moose::Error::Default;
2
3 use strict;
4 use warnings;
5
6 use Carp::Heavy;
7
8 use Moose::Error::Util;
9
10 use base 'Class::MOP::Object';
11
12 sub new {
13     my ( $self, @args ) = @_;
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.
17     if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
18         $self->create_error_croak( @args );
19     }
20     else {
21         $self->create_error_confess( @args );
22     }
23 }
24
25 sub _inline_new {
26     my ( $self, %args ) = @_;
27
28     my $depth = ($args{depth} || 0) - 1;
29     return 'Moose::Error::Util::create_error('
30       . 'message => ' . $args{message} . ', '
31       . 'depth   => ' . $depth         . ', '
32   . ')';
33 }
34
35 sub create_error_croak {
36     my ( $self, @args ) = @_;
37     return Moose::Error::Util::create_error_croak(@args);
38 }
39
40 sub create_error_confess {
41     my ( $self, @args ) = @_;
42     return Moose::Error::Util::create_error_confess(@args);
43 }
44
45 1;
46
47 # ABSTRACT: L<Carp> based error generation for Moose.
48
49 __END__
50
51 =pod
52
53 =head1 DESCRIPTION
54
55 This class implements L<Carp> based error generation.
56
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.
62
63 =head1 METHODS
64
65 =over 4
66
67 =item B<< Moose::Error::Default->new(@args) >>
68
69 Create a new error. Delegates to C<create_error_confess> or
70 C<create_error_croak>.
71
72 =item B<< $error->create_error_confess(@args) >>
73
74 =item B<< $error->create_error_croak(@args) >>
75
76 Creates a new errors string of the specified style.
77
78 =back
79
80 =cut
81
82