[Moose-commits] r7766 - Moose/trunk/lib/Moose/Util

autarch at code2.0beta.co.uk autarch at code2.0beta.co.uk
Sun Feb 22 04:22:37 GMT 2009


Author: autarch
Date: 2009-02-21 20:22:36 -0800 (Sat, 21 Feb 2009)
New Revision: 7766

Modified:
   Moose/trunk/lib/Moose/Util/TypeConstraints.pm
Log:
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.


Modified: Moose/trunk/lib/Moose/Util/TypeConstraints.pm
===================================================================
--- Moose/trunk/lib/Moose/Util/TypeConstraints.pm	2009-02-22 03:37:25 UTC (rev 7765)
+++ Moose/trunk/lib/Moose/Util/TypeConstraints.pm	2009-02-22 04:22:36 UTC (rev 7766)
@@ -288,7 +288,9 @@
         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 @@
     _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] } }




More information about the Moose-commits mailing list