Add release date
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
CommitLineData
bf6fa6b3 1package Moose::Error::Default;
2
c0e91e5f 3use strict;
4use warnings;
5
0f8380b0 6our $VERSION = '0.86';
ae18d5ec 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
41daa828 10use Carp::Heavy;
11
12
bf6fa6b3 13sub new {
14 my ( $self, @args ) = @_;
41daa828 15 $self->create_error_confess( @args );
bf6fa6b3 16}
17
18sub create_error_croak {
19 my ( $self, @args ) = @_;
41daa828 20 $self->_create_error_carpmess( @args );
bf6fa6b3 21}
22
23sub create_error_confess {
24 my ( $self, @args ) = @_;
25 $self->_create_error_carpmess( @args, longmess => 1 );
26}
27
28sub _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
52Moose::Error::Default - L<Carp> based error generation for Moose.
53
54=head1 DESCRIPTION
55
56This class implements L<Carp> based error generation.
57
58The default behavior is like L<Moose::Error::Confess>.
59
60=head1 METHODS
61
62=over 4
63
64=item new @args
65
66Create a new error. Delegates to C<create_error_confess>.
67
68=item create_error_confess @args
69
70=item create_error_croak @args
71
72Creates a new errors string of the specified style.
73
74=back
75
76=cut
77
78