From: gfx Date: Tue, 20 Jul 2010 10:22:23 +0000 (+0900) Subject: Import a latest test file for register_type_constraints() and fix tc class X-Git-Tag: 0.63~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=184f8f53393b72298e3de0132bf8c06d5909dcb9 Import a latest test file for register_type_constraints() and fix tc class --- diff --git a/lib/Mouse/Meta/TypeConstraint.pm b/lib/Mouse/Meta/TypeConstraint.pm index 1d3ba78..6dd1904 100644 --- a/lib/Mouse/Meta/TypeConstraint.pm +++ b/lib/Mouse/Meta/TypeConstraint.pm @@ -1,9 +1,11 @@ package Mouse::Meta::TypeConstraint; use Mouse::Util qw(:meta); # enables strict and warnings +use Scalar::Util (); use overload 'bool' => sub (){ 1 }, # always true '""' => sub { $_[0]->name }, # stringify to tc name + '0+' => sub { Scalar::Util::refaddr($_[0]) }, '|' => sub { # or-combination require Mouse::Util::TypeConstraints; return Mouse::Util::TypeConstraints::find_or_parse_type_constraint( @@ -14,7 +16,8 @@ use overload fallback => 1; sub new { - my($class, %args) = @_; + my $class = shift; + my %args = @_ == 1 ? %{$_[0]} : @_; $args{name} = '__ANON__' if !defined $args{name}; diff --git a/t/040_type_constraints/010_misc_type_tests.t b/t/040_type_constraints/010_misc_type_tests.t index 43fcebc..f5cc487 100644 --- a/t/040_type_constraints/010_misc_type_tests.t +++ b/t/040_type_constraints/010_misc_type_tests.t @@ -3,8 +3,9 @@ use strict; use warnings; -use Test::More tests => 11; +use Test::More; use Test::Exception; +use Scalar::Util qw(refaddr); BEGIN { use_ok('Mouse::Util::TypeConstraints'); @@ -65,3 +66,24 @@ ok $subtype2 => 'made a subtype of our subtype'; "correct error thrown" ); } + +{ + for my $t (qw(Bar Foo)) { + my $tc = Mouse::Meta::TypeConstraint->new({ + name => $t, + }); + + Mouse::Util::TypeConstraints::register_type_constraint($tc); + } + + my $foo = Mouse::Util::TypeConstraints::find_type_constraint('Foo'); + my $bar = Mouse::Util::TypeConstraints::find_type_constraint('Bar'); + + ok(!$foo->is_a_type_of($bar), "Foo type is not equal to Bar type"); + ok( $foo->is_a_type_of($foo), "Foo equals Foo"); + ok( 0+$foo == refaddr($foo), "overloading works"); +} + +ok $subtype1, "type constraint boolean overload works"; + +done_testing;