From: Matt S Trout Date: Thu, 3 Dec 2009 14:54:50 +0000 (+0000) Subject: create custom error thrower to avoid closing over meta object just for ->throw_error X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0fc4a7ab8621aeee2cf26874a5f2395b46af10c;p=gitmo%2FMooseX-Antlers.git create custom error thrower to avoid closing over meta object just for ->throw_error --- diff --git a/lib/MooseX/Antlers/ErrorThrower.pm b/lib/MooseX/Antlers/ErrorThrower.pm new file mode 100644 index 0000000..dad5191 --- /dev/null +++ b/lib/MooseX/Antlers/ErrorThrower.pm @@ -0,0 +1,7 @@ +package MooseX::Antlers::ErrorThrower; + +use Carp (); + +sub throw_error { confess $_[1]; } + +1; diff --git a/lib/MooseX/Antlers/EvalTracker.pm b/lib/MooseX/Antlers/EvalTracker.pm index e2cc227..1f5daf4 100644 --- a/lib/MooseX/Antlers/EvalTracker.pm +++ b/lib/MooseX/Antlers/EvalTracker.pm @@ -1,6 +1,7 @@ package MooseX::Antlers::EvalTracker; use Moose; +use MooseX::Antlers::ErrorThrower; use Scalar::Util qw(weaken refaddr); use PadWalker qw(closed_over); use Sub::Identify qw(sub_fullname); @@ -25,14 +26,13 @@ sub _build__our_eval_closure { # _eval_closure returns a CODE ref and we want that too sub { my $self = shift; - # ... screwed over here by $attr->default(...) and ->trigger(...) - # in the bloody inlined subs. XXX slap stevan, fix Moose - # until we stop passing these let's make anything that uses it - # crash out so at least we don't break anything - #delete @{$_[0]}{qw($meta $attr)}; - my $cr = $self->$orig(@_); - $eval_tracker->_eval_closure_called_for($cr => @_); - return $cr; + if ($_[0]->{'$attr'} || $_[0]->{'$attrs'}) { + die "Closing over meta-attribute, can't handle this. Suspect you used initializer - can't support that yet, sorry. Patches welcome."; + } + $_[0]->{'$meta'} = \'MooseX::Antlers::ErrorThrower'; + my ($cr, $e) = $self->$orig(@_); + $eval_tracker->_eval_closure_called_for($cr => @_) unless $e; + return ($cr, $e); }; } diff --git a/t/track_eval.t b/t/track_eval.show similarity index 100% rename from t/track_eval.t rename to t/track_eval.show