From: Florian Ragwitz Date: Fri, 5 Feb 2010 18:57:04 +0000 (+0100) Subject: Make ScalarRef accept references to references. X-Git-Tag: 0.96~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=150e51428b8826acfd85b66a55e1a473982843e4;p=gitmo%2FMoose.git Make ScalarRef accept references to references. --- diff --git a/Changes b/Changes index e6a3d76..9de8264 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,10 @@ for, noteworthy changes. constraint for whatever the reference points to. (Closes RT#50857) (Michael G. Schwern, Florian Ragwitz) + [BUG FIXES] + * ScalarRef now accepts references to other references. (Closes RT#50934) + (Michael G. Schwern) + 0.95 Thu, Feb 4, 2010 [NEW FEATURES] diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 88ddf81..cfea18f 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -717,7 +717,7 @@ $REGISTRY->add_type_constraint( name => 'ScalarRef', package_defined_in => __PACKAGE__, parent => find_type_constraint('Ref'), - constraint => sub { ref($_) eq 'SCALAR' }, + constraint => sub { ref($_) eq 'SCALAR' || ref($_) eq 'REF' }, optimized => \&Moose::Util::TypeConstraints::OptimizedConstraints::ScalarRef, constraint_generator => sub { diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm index 6486125..7c735ad 100644 --- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm +++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm @@ -25,7 +25,7 @@ sub Num { !ref($_[0]) && looks_like_number($_[0]) } sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } -sub ScalarRef { ref($_[0]) eq 'SCALAR' } +sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' } sub ArrayRef { ref($_[0]) eq 'ARRAY' } sub HashRef { ref($_[0]) eq 'HASH' } sub CodeRef { ref($_[0]) eq 'CODE' } diff --git a/t/040_type_constraints/003_util_std_type_constraints.t b/t/040_type_constraints/003_util_std_type_constraints.t index 00c1179..36f85c1 100644 --- a/t/040_type_constraints/003_util_std_type_constraints.t +++ b/t/040_type_constraints/003_util_std_type_constraints.t @@ -191,6 +191,7 @@ ok(!defined ScalarRef([]), '... ScalarRef rejects anything which i ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef'); ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef'); ok(defined ScalarRef($SCALAR_REF), '... ScalarRef accepts anything which is a ScalarRef'); +ok(defined ScalarRef(\$SCALAR_REF), '... ScalarRef accepts references to references'); ok(!defined ScalarRef($GLOB), '... ScalarRef rejects anything which is not a ScalarRef'); ok(!defined ScalarRef($GLOB_REF), '... ScalarRef rejects anything which is not a ScalarRef'); ok(!defined ScalarRef($fh), '... ScalarRef rejects anything which is not a ScalarRef');