} else {
$type_constraint = $class->create_base_type_constraint($name);
}
+
$type_constraint = defined($type_constraint) ? $type_constraint
: MooseX::Types::UndefinedType->new($name);
if(my $arg = shift @_) {
if(blessed $arg && $arg->isa('Moose::Meta::TypeConstraint')) {
return bless {'__type_constraint'=>$arg}, $class;
- } elsif(blessed $arg && $arg->isa('MooseX::Types::UndefinedType')) {
+ } elsif(
+ blessed $arg &&
+ $arg->isa('MooseX::Types::UndefinedType')
+ ) {
## stub in case we'll need to handle these types differently
return bless {'__type_constraint'=>$arg}, $class;
} elsif(blessed $arg) {
croak "Argument cannot be '$arg'";
}
} else {
- croak "This method [new] requires a single argument of 'arg'.";
+ croak "This method [new] requires a single argument.";
}
}
if($self->__type_constraint->can($method)) {
return $self->__type_constraint->$method(@args);
} else {
- croak "Method '$method' is not supported";
+ croak "Method '$method' is not supported for ". ref($self->__type_constraint);
}
}
--- /dev/null
+## Test case inspired by Stevan Little
+
+BEGIN {
+ package MooseX::Types::Test::Recursion;
+
+ use Moose;
+
+ use Moose::Util::TypeConstraints;
+ use MooseX::Types::Moose qw(Str HashRef);
+ use MooseX::Types -declare => [qw(
+ RecursiveHashRef
+ )];
+
+ ## Define a recursive subtype and Cthulhu save us.
+ subtype RecursiveHashRef()
+ => as HashRef[Str() | RecursiveHashRef()];
+}
+
+{
+ package MooseX::Types::Test::Recursion::TestRunner;
+
+ BEGIN {
+ use Test::More 'no_plan';
+ use Data::Dump qw/dump/;
+
+ MooseX::Types::Test::Recursion->import(':all');
+ };
+
+
+ ok RecursiveHashRef->check({key=>"value"})
+ => 'properly validated {key=>"value"}';
+
+ ok RecursiveHashRef->check({key=>{subkey=>"value"}})
+ => 'properly validated {key=>{subkey=>"value"}}';
+
+
+ warn dump RecursiveHashRef();
+}
+
+
+
+
+
+