return _create_type_constraint(@_);
}
+ if ( @_ == 1 && ! ref $_[0] ) {
+ __PACKAGE__->_throw_error('A subtype cannot consist solely of a name, it must have a parent');
+ }
+
# The blessed check is mostly to accommodate MooseX::Types, which
# uses an object which overloads stringification as a type name.
my $name = ref $_[0] && ! blessed $_[0] ? undef : shift;
use strict;
use warnings;
-use Test::More tests => 84;
+use Test::More tests => 85;
use Test::Exception;
use Scalar::Util ();
}
{
- my $subtype = subtype 'ArrayRef[Num|Str]';
+ my $subtype = subtype as 'ArrayRef[Num|Str]';
isa_ok( $subtype, 'Moose::Meta::TypeConstraint', 'got an anon subtype' );
is( $subtype->parent->name, 'ArrayRef[Num|Str]', 'parent is ArrayRef[Num|Str]' );
ok( ! $subtype->has_message, 'subtype has no message' );
ok( ! $subtype->check('Foo'), 'constraint reject Foo' );
}
+{
+ throws_ok { subtype 'Foo' } qr/cannot consist solely of a name/,
+ 'Cannot call subtype with a single string argument';
+}
# Back-compat for being called without sugar. Previously, calling with
# sugar was indistinguishable from calling directly.