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