Revision history for Perl extension Moose
+0.19
+ * Moose::Util::TypeConstraints
+ - type now supports messages as well
+ (thanks to phaylon for finding this)
+ - added tests for this
+
0.18 Sat. March 10, 2007
~~ Many, many documentation updates ~~
use strict;
use warnings;
-use Test::More tests => 32;
+use Test::More tests => 36;
use Test::Exception;
use Scalar::Util ();
}
type Number => where { Scalar::Util::looks_like_number($_) };
-type String => where { !ref($_) && !Number($_) };
+type String
+ => where { !ref($_) && !Number($_) }
+ => message { "This is not a string ($_)" };
subtype Natural
=> as Number
"Validation failed for 'Natural' failed",
'... validated unsuccessfully (got error)');
+my $string = find_type_constraint('String');
+isa_ok($string, 'Moose::Meta::TypeConstraint');
+ok($string->has_message, '... it does have a message');
+
+ok(!defined($string->validate("Five")), '... validated successfully (no error)');
+
+is($string->validate(5),
+"This is not a string (5)",
+'... validated unsuccessfully (got error)');