From: Chip Date: Thu, 30 Dec 2010 21:13:31 +0000 (-0800) Subject: avoid unnecessary copies in Str validation X-Git-Tag: 1.9900~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=720f6a582283534d6e9dc11d28d0904b9171b05b;p=gitmo%2FMoose.git avoid unnecessary copies in Str validation --- diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm index 9d54897..5d54359 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' + || ref(\(my $value = $_[0])) eq 'SCALAR') } sub Num { !ref($_[0]) && looks_like_number($_[0]) }