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');
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',