0.94
* Moose::Cookbook::Basics::Recipe4
- Grammar error [rt.cpan.org #51791] (Amir E. Aharoni)
+ * Moose::Util::TypeConstraints
+ - Changed Str constraint to accept magic lvalue strings like one gets
+ from substr et al, again. (sorear)
0.93 Thu, Nov 19, 2009
* Moose::Object
sub Ref { ref($_[0]) }
-sub Str { defined($_[0]) && ref(\$_[0]) eq 'SCALAR' }
+# We 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'
+}
sub Num { !ref($_[0]) && looks_like_number($_[0]) }
use strict;
use warnings;
-use Test::More tests => 297;
+use Test::More tests => 298;
use Test::Exception;
use Scalar::Util ();
use_ok('Moose::Util::TypeConstraints');
}
+my $STRING = "foo";
+
my $SCALAR_REF = \(my $var);
no warnings 'once'; # << I *hates* that warning ...
ok(defined Str(100), '... Str accepts anything which is a Str');
ok(defined Str(''), '... Str accepts anything which is a Str');
ok(defined Str('Foo'), '... Str accepts anything which is a Str');
+ok(defined Str(substr($STRING,0,1)),'... Str accepts anything which is a Str');
ok(!defined Str([]), '... Str rejects anything which is not a Str');
ok(!defined Str({}), '... Str rejects anything which is not a Str');
ok(!defined Str(sub {}), '... Str rejects anything which is not a Str');