Commit | Line | Data |
bf6fa6b3 |
1 | package Moose::Error::Default; |
2 | |
c0e91e5f |
3 | use strict; |
4 | use warnings; |
5 | |
b6cca0d5 |
6 | our $VERSION = '1.14'; |
ae18d5ec |
7 | $VERSION = eval $VERSION; |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
41daa828 |
10 | use Carp::Heavy; |
11 | |
4f5ca7c5 |
12 | use base 'Class::MOP::Object'; |
13 | |
41daa828 |
14 | |
bf6fa6b3 |
15 | sub new { |
16 | my ( $self, @args ) = @_; |
41daa828 |
17 | $self->create_error_confess( @args ); |
bf6fa6b3 |
18 | } |
19 | |
20 | sub create_error_croak { |
21 | my ( $self, @args ) = @_; |
41daa828 |
22 | $self->_create_error_carpmess( @args ); |
bf6fa6b3 |
23 | } |
24 | |
25 | sub create_error_confess { |
26 | my ( $self, @args ) = @_; |
27 | $self->_create_error_carpmess( @args, longmess => 1 ); |
28 | } |
29 | |
30 | sub _create_error_carpmess { |
31 | my ( $self, %args ) = @_; |
32 | |
33 | my $carp_level = 3 + ( $args{depth} || 1 ); |
41daa828 |
34 | local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though |
bf6fa6b3 |
35 | |
36 | my @args = exists $args{message} ? $args{message} : (); |
37 | |
38 | if ( $args{longmess} || $Carp::Verbose ) { |
39 | local $Carp::CarpLevel = ( $Carp::CarpLevel || 0 ) + $carp_level; |
40 | return Carp::longmess(@args); |
41daa828 |
41 | } else { |
42 | return Carp::ret_summary($carp_level, @args); |
bf6fa6b3 |
43 | } |
44 | } |
45 | |
46 | __PACKAGE__ |
47 | |
48 | __END__ |
49 | |
50 | =pod |
51 | |
52 | =head1 NAME |
53 | |
54 | Moose::Error::Default - L<Carp> based error generation for Moose. |
55 | |
56 | =head1 DESCRIPTION |
57 | |
58 | This class implements L<Carp> based error generation. |
59 | |
60 | The default behavior is like L<Moose::Error::Confess>. |
61 | |
62 | =head1 METHODS |
63 | |
64 | =over 4 |
65 | |
66 | =item new @args |
67 | |
68 | Create a new error. Delegates to C<create_error_confess>. |
69 | |
70 | =item create_error_confess @args |
71 | |
72 | =item create_error_croak @args |
73 | |
74 | Creates a new errors string of the specified style. |
75 | |
76 | =back |
77 | |
78 | =cut |
79 | |
80 | |