From: Jesse Luehrs Date: Mon, 25 Apr 2011 23:58:49 +0000 (-0500) Subject: actually, can't do that, since Moose::Error::Default isa CMOP::Object X-Git-Tag: 2.0100~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8748a8e8065600bdf8ba0ac8539aa2d7b444df71;p=gitmo%2FMoose.git actually, can't do that, since Moose::Error::Default isa CMOP::Object --- diff --git a/lib/Moose/Error/Confess.pm b/lib/Moose/Error/Confess.pm index 74622b3..c7ddf44 100644 --- a/lib/Moose/Error/Confess.pm +++ b/lib/Moose/Error/Confess.pm @@ -14,7 +14,7 @@ sub _inline_new { my ( $self, %args ) = @_; my $depth = ($args{depth} || 0) - 1; - return $self . '->new(' + return 'Moose::Error::Util::create_error_confess(' . 'message => ' . $args{message} . ', ' . 'depth => ' . $depth . ', ' . ')'; diff --git a/lib/Moose/Error/Croak.pm b/lib/Moose/Error/Croak.pm index b6a9a9f..448ee36 100644 --- a/lib/Moose/Error/Croak.pm +++ b/lib/Moose/Error/Croak.pm @@ -14,7 +14,7 @@ sub _inline_new { my ( $self, %args ) = @_; my $depth = ($args{depth} || 0) - 1; - return $self . '->new(' + return 'Moose::Error::Util::create_error_croak(' . 'message => ' . $args{message} . ', ' . 'depth => ' . $depth . ', ' . ')'; diff --git a/lib/Moose/Error/Default.pm b/lib/Moose/Error/Default.pm index 7944cd8..b3c2f87 100644 --- a/lib/Moose/Error/Default.pm +++ b/lib/Moose/Error/Default.pm @@ -6,12 +6,17 @@ use warnings; use Carp::Heavy; use Class::MOP::MiniTrait; +use Moose::Error::Util; + use base 'Class::MOP::Object'; Class::MOP::MiniTrait::apply(__PACKAGE__, 'Moose::Meta::Object::Trait'); sub new { my ( $self, @args ) = @_; + # can't use Moose::Error::Util::create_error here because that would break + # inheritance. we don't care about that for the inlined version, because + # the inlined versions are explicitly not inherited. if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') { $self->create_error_croak( @args ); } @@ -24,7 +29,7 @@ sub _inline_new { my ( $self, %args ) = @_; my $depth = ($args{depth} || 0) - 1; - return $self . '->new(' + return 'Moose::Error::Util::create_error(' . 'message => ' . $args{message} . ', ' . 'depth => ' . $depth . ', ' . ')'; @@ -32,28 +37,12 @@ sub _inline_new { sub create_error_croak { my ( $self, @args ) = @_; - $self->_create_error_carpmess( @args ); + return Moose::Error::Util::create_error_croak(@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 = 4 + ( $args{depth} || 0 ); - 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); - } + return Moose::Error::Util::create_error_confess(@args); } 1; diff --git a/lib/Moose/Error/Util.pm b/lib/Moose/Error/Util.pm new file mode 100644 index 0000000..af1c7ce --- /dev/null +++ b/lib/Moose/Error/Util.pm @@ -0,0 +1,45 @@ +package # pretend this doesn't exist, because it shouldn't + Moose::Error::Util; + +use strict; +use warnings; + +# this intentionally exists to have a place to put this logic that doesn't +# involve loading Class::MOP, so... don't do that + +use Carp::Heavy; + +sub _create_error_carpmess { + my %args = @_; + + my $carp_level = 3 + ( $args{depth} || 0 ); + 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); + } +} + +sub create_error_croak { + _create_error_carpmess(@_); +} + +sub create_error_confess { + _create_error_carpmess(@_, longmess => 1); +} + +sub create_error { + if (defined $ENV{MOOSE_ERROR_STYLE} && $ENV{MOOSE_ERROR_STYLE} eq 'croak') { + create_error_croak(@_); + } + else { + create_error_confess(@_); + } +} + +1;