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