Now that I look at it again, I think I can eliminate the do{} block.  But
any problems with the approach?

Author: Chip <[email protected]>
Date:   Wed Dec 29 20:51:52 2010 -0800

    avoid unnecessary copy during optimized Str test

diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
index 9d54897..59c7c40 100644
--- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
+++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
@@ -15,11 +15,12 @@ sub Value { defined($_[0]) && !ref($_[0]) }

 sub Ref { ref($_[0]) }

-# We need to use a temporary here to flatten LVALUEs, for instance as in
+# We might need to use a temporary here to flatten LVALUEs, for instance as
in
 # Str(substr($_,0,255)).
 sub Str {
-    my $value = $_[0];
-    defined($value) && ref(\$value) eq 'SCALAR'
+    defined($_[0])
+      && (ref(\$_[0]) eq 'SCALAR'
+          || do { my $value = $_[0]; ref(\$value) eq 'SCALAR' })
 }

 sub Num { !ref($_[0]) && looks_like_number($_[0]) }

Reply via email to