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]
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 {
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' }
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');