don't calculate the cache key unless we're going to be caching
Jesse Luehrs [Wed, 20 Apr 2011 03:35:47 +0000 (22:35 -0500)]
lib/Class/MOP/Package.pm

index bc5c6ca..d3930ff 100644 (file)
@@ -97,10 +97,13 @@ sub create {
 
         my $cache_ok = delete $options{cache};
 
-        my $cache_key = $class->_anon_cache_key(%options);
+        my $cache_key;
+        if ($cache_ok) {
+            $cache_key = $class->_anon_cache_key(%options);
 
-        if ($cache_ok && defined $ANON_PACKAGE_CACHE{$cache_key}) {
-            return $ANON_PACKAGE_CACHE{$cache_key};
+            if (defined $ANON_PACKAGE_CACHE{$cache_key}) {
+                return $ANON_PACKAGE_CACHE{$cache_key};
+            }
         }
 
         $options{weaken} = !$cache_ok unless exists $options{weaken};