From: Dave Rolsky Date: Sun, 22 Feb 2009 04:22:36 +0000 (+0000) Subject: A couple changes to make MX::Types keep working. X-Git-Tag: 0.71_01~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6c0c589a5fd2bef7e04b55218dfb89f5bedb027;p=gitmo%2FMoose.git A couple changes to make MX::Types keep working. First, make subtype handle a first arg which is a blessed reference (which MX::Types will cause to happen). Second, kill the prototype on as() and use a nasty hack to make it keep working. --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 733e297..5f20933 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -288,7 +288,9 @@ sub subtype { return _create_type_constraint(@_); } - my $name = ref $_[0] ? undef : shift; + # 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; my %p = map { %{$_} } @_; @@ -332,7 +334,20 @@ sub coerce { _install_type_coercions($type_name, \@coercion_map); } -sub as ($) { { as => $_[0] } } +# The trick of returning @_ lets us avoid having to specify a +# prototype. Perl will parse this: +# +# subtype 'Foo' +# => as 'Str' +# => where { ... } +# +# as this: +# +# subtype( 'Foo', as( 'Str', where { ... } ) ); +# +# If as() returns all it's extra arguments, this just works, and +# preserves backwards compatibility. +sub as { { as => shift }, @_ } sub where (&) { { where => $_[0] } } sub message (&) { { message => $_[0] } } sub optimize_as (&) { { optimize_as => $_[0] } }