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