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