From: Robert 'phaylon' Sedlacek <rs@474.at>
Date: Sat, 24 Mar 2007 18:05:20 +0000 (+0000)
Subject: type constraints now stringify to their name (phaylon)
X-Git-Tag: 0_19~1
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=900466d6799e621a65ad99b7653ec6ff9292b79d;p=gitmo%2FMoose.git

type constraints now stringify to their name (phaylon)
---

diff --git a/Changes b/Changes
index e1ce698..c64a5b3 100644
--- a/Changes
+++ b/Changes
@@ -16,6 +16,10 @@ Revision history for Perl extension Moose
         things like &new)
         - added tests and docs for this
 
+    * Moose::Meta::TypeConstraint
+      - type constraints now stringify to their names.
+        - added test for this
+
     * misc.
       - added test for working with Module::Refresh 
 
@@ -552,4 +556,4 @@ Revision history for Perl extension Moose
 	    full fledges meta-objects
 
 0.01 Wed. March 15, 2006
-    - Moooooooooooooooooose!!!
\ No newline at end of file
+    - Moooooooooooooooooose!!!
diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm
index 0326a14..8295230 100644
--- a/lib/Moose/Meta/TypeConstraint.pm
+++ b/lib/Moose/Meta/TypeConstraint.pm
@@ -5,6 +5,9 @@ use strict;
 use warnings;
 use metaclass;
 
+use overload '""'     => sub { shift->name },   # stringify to tc name
+             fallback => 1;
+
 use Sub::Name    'subname';
 use Carp         'confess';
 use Scalar::Util 'blessed';
diff --git a/t/050_util_type_constraints.t b/t/050_util_type_constraints.t
index 8e5b96a..37a7fa9 100644
--- a/t/050_util_type_constraints.t
+++ b/t/050_util_type_constraints.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 36;
+use Test::More tests => 37;
 use Test::Exception;
 
 use Scalar::Util ();
@@ -30,6 +30,10 @@ Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
 
 ok(Number(5), '... this is a Num');
 ok(!defined(Number('Foo')), '... this is not a Num');
+{
+    my $number_tc = Moose::Util::TypeConstraints::find_type_constraint('Number');
+    is("$number_tc", 'Number', '... type constraint stringifies to name');
+}
 
 ok(String('Foo'), '... this is a Str');
 ok(!defined(String(5)), '... this is not a Str');