[Moose-commits] r7790 - in Moose/trunk: lib/Moose/Util
t/040_type_constraints
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Wed Feb 25 19:55:15 GMT 2009
Author: autarch
Date: 2009-02-25 11:55:15 -0800 (Wed, 25 Feb 2009)
New Revision: 7790
Modified:
Moose/trunk/lib/Moose/Util/TypeConstraints.pm
Moose/trunk/t/040_type_constraints/001_util_type_constraints.t
Log:
Catch calls to subtype that just provide a name (and no parent) and barf on them.
Modified: Moose/trunk/lib/Moose/Util/TypeConstraints.pm
===================================================================
--- Moose/trunk/lib/Moose/Util/TypeConstraints.pm 2009-02-25 19:50:15 UTC (rev 7789)
+++ Moose/trunk/lib/Moose/Util/TypeConstraints.pm 2009-02-25 19:55:15 UTC (rev 7790)
@@ -288,6 +288,10 @@
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;
Modified: Moose/trunk/t/040_type_constraints/001_util_type_constraints.t
===================================================================
--- Moose/trunk/t/040_type_constraints/001_util_type_constraints.t 2009-02-25 19:50:15 UTC (rev 7789)
+++ Moose/trunk/t/040_type_constraints/001_util_type_constraints.t 2009-02-25 19:55:15 UTC (rev 7790)
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 84;
+use Test::More tests => 85;
use Test::Exception;
use Scalar::Util ();
@@ -148,7 +148,7 @@
}
{
- 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' );
@@ -185,6 +185,10 @@
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.
More information about the Moose-commits
mailing list