Moose::Error::Default - L<Carp> based error generation for Moose.


Moose documentation Contained in the Moose distribution.

Index


Code Index:

NAME

Top

Moose::Error::Default - Carp based error generation for Moose.

VERSION

Top

version 2.0010

DESCRIPTION

Top

This class implements Carp based error generation.

The default behavior is like Moose::Error::Confess. To override this to default to Moose::Error::Croak's behaviour on a system wide basis, set the MOOSE_ERROR_STYLE environment variable to croak. The use of this environment variable is considered experimental, and may change in a future release.

METHODS

Top

Moose::Error::Default->new(@args)

Create a new error. Delegates to create_error_confess or create_error_croak.

$error->create_error_confess(@args)
$error->create_error_croak(@args)

Creates a new errors string of the specified style.

AUTHOR

Top

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE

Top


Moose documentation Contained in the Moose distribution.

package Moose::Error::Default;
BEGIN {
  $Moose::Error::Default::AUTHORITY = 'cpan:STEVAN';
}
BEGIN {
  $Moose::Error::Default::VERSION = '2.0010';
}

use strict;
use warnings;

use Carp::Heavy;
use Class::MOP::MiniTrait;

use base 'Class::MOP::Object';

Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait');

sub new {
    my ( $self, @args ) = @_;
    if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') {
        $self->create_error_croak( @args );
    }
    else {
        $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);
    }
}

1;

# ABSTRACT: L<Carp> based error generation for Moose.




__END__