create custom error thrower to avoid closing over meta object just for ->throw_error
Matt S Trout [Thu, 3 Dec 2009 14:54:50 +0000 (14:54 +0000)]
lib/MooseX/Antlers/ErrorThrower.pm [new file with mode: 0644]
lib/MooseX/Antlers/EvalTracker.pm
t/track_eval.show [moved from t/track_eval.t with 100% similarity]

diff --git a/lib/MooseX/Antlers/ErrorThrower.pm b/lib/MooseX/Antlers/ErrorThrower.pm
new file mode 100644 (file)
index 0000000..dad5191
--- /dev/null
@@ -0,0 +1,7 @@
+package MooseX::Antlers::ErrorThrower;
+
+use Carp ();
+
+sub throw_error { confess $_[1]; }
+
+1;
index e2cc227..1f5daf4 100644 (file)
@@ -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);
   };
 }
 
similarity index 100%
rename from t/track_eval.t
rename to t/track_eval.show