created the decorator and got it hooked up, made sure all the old tests pass
John Napiorkowski [Fri, 22 Aug 2008 21:15:53 +0000 (21:15 +0000)]
lib/MooseX/Types.pm
lib/MooseX/Types/TypeDecorator.pm [new file with mode: 0644]

index f97ff02..eb443bf 100644 (file)
@@ -11,6 +11,7 @@ MooseX::Types - Organise your Moose types in libraries
 #use strict;
 
 use Moose::Util::TypeConstraints;
+use MooseX::Types::TypeDecorator;
 use MooseX::Types::Base             ();
 use MooseX::Types::Util             qw( filter_tags );
 use MooseX::Types::UndefinedType;
@@ -301,9 +302,12 @@ yet defined.
 
 sub type_export_generator {
     my ($class, $type, $full) = @_;
-    return sub { 
-        return find_type_constraint($full)
-            || MooseX::Types::UndefinedType->new($full);
+    return sub {
+        my @args = @_;
+        use Data::Dump qw/dump/; warn @args;
+        my $type_constraint = find_type_constraint($full)
+         || MooseX::Types::UndefinedType->new($full);
+        return MooseX::Types::TypeDecorator->new(type_constraint=>$type_constraint);
     };
 }
 
diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm
new file mode 100644 (file)
index 0000000..42cd141
--- /dev/null
@@ -0,0 +1,76 @@
+package MooseX::Types::TypeDecorator;
+
+use Moose;
+use Moose::Util::TypeConstraints;
+use Moose::Meta::TypeConstraint ();
+
+use overload(
+    '""' => sub {
+        shift->type_constraint->name;  
+    },
+);
+
+=head1 NAME
+
+MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
+
+=head1 DESCRIPTION
+
+This is a decorator object that contains an underlying type constraint.  We use
+this to control access to the type constraint and to add some features.
+
+=head1 TYPES
+
+The following types are defined in this class.
+
+=head2 Moose::Meta::TypeConstraint
+
+Used to make sure we can properly validate incoming type constraints.
+
+=cut
+
+class_type 'Moose::Meta::TypeConstraint';
+
+=head2 MooseX::Types::UndefinedType
+
+Used since sometimes our constraint is an unknown type.
+
+=cut
+
+class_type 'MooseX::Types::UndefinedType';
+
+=head1 ATTRIBUTES
+
+This class defines the following attributes
+
+=head2 type_constraint
+
+This is the type constraint that we are delegating
+
+=cut
+
+has 'type_constraint' => (
+    is=>'ro',
+    isa=>'Moose::Meta::TypeConstraint|MooseX::Types::UndefinedType',
+    handles=>[
+        Moose::Meta::TypeConstraint->meta->compute_all_applicable_methods,
+        "_compiled_type_constraint",
+    ],
+);
+
+=head1 METHODS
+
+This class defines the following methods.
+
+=head1 AUTHOR AND COPYRIGHT
+
+John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>
+
+=head1 LICENSE
+
+This program is free software; you can redistribute it and/or modify
+it under the same terms as perl itself.
+
+=cut
+
+1;