the error classes should be cmop objects
[gitmo/Moose.git] / lib / Moose / Error / Default.pm
CommitLineData
bf6fa6b3 1package Moose::Error::Default;
2
c0e91e5f 3use strict;
4use warnings;
5
b6cca0d5 6our $VERSION = '1.14';
ae18d5ec 7$VERSION = eval $VERSION;
8our $AUTHORITY = 'cpan:STEVAN';
9
41daa828 10use Carp::Heavy;
11
4f5ca7c5 12use base 'Class::MOP::Object';
13
41daa828 14
bf6fa6b3 15sub new {
16 my ( $self, @args ) = @_;
41daa828 17 $self->create_error_confess( @args );
bf6fa6b3 18}
19
20sub create_error_croak {
21 my ( $self, @args ) = @_;
41daa828 22 $self->_create_error_carpmess( @args );
bf6fa6b3 23}
24
25sub create_error_confess {
26 my ( $self, @args ) = @_;
27 $self->_create_error_carpmess( @args, longmess => 1 );
28}
29
30sub _create_error_carpmess {
31 my ( $self, %args ) = @_;
32
33 my $carp_level = 3 + ( $args{depth} || 1 );
41daa828 34 local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
bf6fa6b3 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);
41daa828 41 } else {
42 return Carp::ret_summary($carp_level, @args);
bf6fa6b3 43 }
44}
45
46__PACKAGE__
47
48__END__
49
50=pod
51
52=head1 NAME
53
54Moose::Error::Default - L<Carp> based error generation for Moose.
55
56=head1 DESCRIPTION
57
58This class implements L<Carp> based error generation.
59
60The default behavior is like L<Moose::Error::Confess>.
61
62=head1 METHODS
63
64=over 4
65
66=item new @args
67
68Create a new error. Delegates to C<create_error_confess>.
69
70=item create_error_confess @args
71
72=item create_error_croak @args
73
74Creates a new errors string of the specified style.
75
76=back
77
78=cut
79
80