f53043659bf0f5b484256d4863e0105fba7d4cef
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
1 package Moose::Error::Default;
2
3 use strict;
4 use warnings;
5
6 our $VERSION   = '1.14';
7 $VERSION = eval $VERSION;
8 our $AUTHORITY = 'cpan:STEVAN';
9
10 use Carp::Heavy;
11
12 use base 'Class::MOP::Object';
13
14
15 sub new {
16     my ( $self, @args ) = @_;
17     $self->create_error_confess( @args );
18 }
19
20 sub create_error_croak {
21     my ( $self, @args ) = @_;
22     $self->_create_error_carpmess( @args );
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 );
34     local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
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);
41     } else {
42         return Carp::ret_summary($carp_level, @args);
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