better error message for when global destruction messes with DEMOLISH
Jesse Luehrs [Sun, 3 May 2009 01:25:55 +0000 (20:25 -0500)]
lib/Moose/Object.pm

index 191e7cb..5d29729 100644 (file)
@@ -72,6 +72,12 @@ sub DEMOLISHALL {
         || Moose::Meta::Class->initialize( ref $self );
 
     foreach my $method ( $meta->find_all_methods_by_name('DEMOLISH') ) {
+        $meta->throw_error(
+            "Couldn't call DEMOLISH on package $method->{class} because"
+          . " global destruction destroyed it first. Make sure all of"
+          . " your instances of $method->{class} are destroyed before"
+          . " global destruction to fix this."
+        ) if !$method->{code} && $in_global_destruction;
         $method->{code}->execute($self, $in_global_destruction);
     }
 }