X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FUtil.pm;h=393bccf9940732a68df841d3c9234356f263be2b;hp=6d107da5c0c0d36c735d8b3bbf74e66458a13ec0;hb=823419c540f9e77090f31f11e04b14477c0372c4;hpb=4cc4f8ed10b2e831b9917b94fdad6e4cdddf9997 diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index 6d107da..393bccf 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -38,13 +38,13 @@ BEGIN{ not_supported - does meta dump + does meta throw_error dump )], groups => { default => [], # export no functions by default # The ':meta' group is 'use metaclass' for Mouse - meta => [qw(does meta dump)], + meta => [qw(does meta dump throw_error)], }, ); @@ -67,7 +67,7 @@ BEGIN{ Mouse::Util->import({ into => 'Mouse::Meta::Method::Accessor::XS' }, ':meta'); return 1; } || 0; - #warn $@ if $@; + warn $@ if $@ && $ENV{MOUSE_XS}; } if(!$xs){ @@ -337,6 +337,22 @@ sub meta :method{ return Mouse::Meta::Class->initialize(ref($_[0]) || $_[0]); } +# general throw_error() method +# $o->throw_error($msg, depth => $leve, longmess => $croak_or_confess) +sub throw_error :method { + my($self, $message, %args) = @_; + + local $Carp::CarpLevel = $Carp::CarpLevel + 1 + ($args{depth} || 0); + local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though + + if(exists $args{longmess} && !$args{longmess}) { + Carp::croak($message); + } + else{ + Carp::confess($message); + } +} + # general dump() method sub dump :method { my($self, $maxdepth) = @_;