From: Graham Knop Date: Sun, 14 Jul 2013 10:45:54 +0000 (-0400) Subject: Remove MooX::Types from xt tests X-Git-Tag: v1.003001~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=124f20461ca14d95e2e1ba48bd9ebf6d6bb76e47;p=gitmo%2FMoo.git Remove MooX::Types from xt tests Having MooX::Types in the xt tests creates a circular dependency for developers. While this isn't strictly a problem, we can easily test the type inflation code without using it. --- diff --git a/xt/moox-types-coercion.t b/xt/type-inflate-coercion.t similarity index 62% rename from xt/moox-types-coercion.t rename to xt/type-inflate-coercion.t index 28ed12c..4d1230a 100644 --- a/xt/moox-types-coercion.t +++ b/xt/type-inflate-coercion.t @@ -2,15 +2,25 @@ use strictures 1; use Test::More; use Test::Fatal; +sub ArrayRef { + my $type = sub { + die unless ref $_[0] && ref $_[0] eq 'ARRAY'; + }; + $Moo::HandleMoose::TYPE_MAP{$type} = sub { + require Moose::Util::TypeConstraints; + Moose::Util::TypeConstraints::find_type_constraint("ArrayRef"); + }; + return ($type, @_); +} + { package ClassWithTypes; $INC{'ClassWithTypes.pm'} = __FILE__; use Moo; - use MooX::Types::MooseLike::Base qw(ArrayRef); - has split_comma => (is => 'ro', isa => ArrayRef, coerce => sub { [ split /,/, $_[0] ] } ); - has split_space => (is => 'ro', isa => ArrayRef, coerce => sub { [ split / /, $_[0] ] } ); - has bad_coerce => (is => 'ro', isa => ArrayRef, coerce => sub { $_[0] } ); + has split_comma => (is => 'ro', isa => ::ArrayRef, coerce => sub { [ split /,/, $_[0] ] } ); + has split_space => (is => 'ro', isa => ::ArrayRef, coerce => sub { [ split / /, $_[0] ] } ); + has bad_coerce => (is => 'ro', isa => ::ArrayRef, coerce => sub { $_[0] } ); } my $o = ClassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d'); diff --git a/xt/moox-types.t b/xt/type-inflate.t similarity index 62% rename from xt/moox-types.t rename to xt/type-inflate.t index 162ed5d..e048fa9 100644 --- a/xt/moox-types.t +++ b/xt/type-inflate.t @@ -6,8 +6,30 @@ use Test::More; use Moo::Role; use Sub::Quote; - use MooX::Types::MooseLike::Base qw(Str); - use MooX::Types::MooseLike::Numeric qw(PositiveInt); + use Moo::HandleMoose (); + + sub Str { + my $type = sub { + die unless defined $_[0] && !ref $_[0]; + }; + $Moo::HandleMoose::TYPE_MAP{$type} = sub { + require Moose::Util::TypeConstraints; + Moose::Util::TypeConstraints::find_type_constraint("Str"); + }; + return ($type, @_); + } + sub PositiveInt { + my $type = sub { + die unless defined $_[0] && !ref $_[0] && $_[0] =~ /^-?\d+/; + }; + $Moo::HandleMoose::TYPE_MAP{$type} = sub { + require Moose::Util::TypeConstraints; + require MooseX::Types::Common::Numeric; + Moose::Util::TypeConstraints::find_type_constraint( + "MooseX::Types::Common::Numeric::PositiveInt"); + }; + return ($type, @_); + } has named_type => ( is => 'ro',