trying to get some tests in place that reflect the desired effect and got a start...
[gitmo/MooseX-Types.git] / lib / MooseX / Types / TypeDecorator.pm
1 package MooseX::Types::TypeDecorator;
2
3 use Moose;
4 use Moose::Util::TypeConstraints ();
5 use Moose::Meta::TypeConstraint ();
6
7 use overload(
8     '""' => sub {
9         shift->type_constraint->name;  
10     },
11     '&' => sub {warn 'got code context'},
12 );
13
14 =head1 NAME
15
16 MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
17
18 =head1 DESCRIPTION
19
20 This is a decorator object that contains an underlying type constraint.  We use
21 this to control access to the type constraint and to add some features.
22
23 =head1 TYPES
24
25 The following types are defined in this class.
26
27 =head2 Moose::Meta::TypeConstraint
28
29 Used to make sure we can properly validate incoming type constraints.
30
31 =cut
32
33 Moose::Util::TypeConstraints::class_type 'Moose::Meta::TypeConstraint';
34
35 =head2 MooseX::Types::UndefinedType
36
37 Used since sometimes our constraint is an unknown type.
38
39 =cut
40
41 Moose::Util::TypeConstraints::class_type 'MooseX::Types::UndefinedType';
42
43 =head1 ATTRIBUTES
44
45 This class defines the following attributes
46
47 =head2 type_constraint
48
49 This is the type constraint that we are delegating
50
51 =cut
52
53 has 'type_constraint' => (
54     is=>'ro',
55     isa=>'Moose::Meta::TypeConstraint|MooseX::Types::UndefinedType',
56     handles=>[
57         grep {
58             $_ ne 'meta' && $_ ne '(""';
59         } map {
60             $_->{name};
61         } Moose::Meta::TypeConstraint->meta->compute_all_applicable_methods,
62     ],
63 );
64
65 =head1 METHODS
66
67 This class defines the following methods.
68
69 =head1 AUTHOR AND COPYRIGHT
70
71 John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>
72
73 =head1 LICENSE
74
75 This program is free software; you can redistribute it and/or modify
76 it under the same terms as perl itself.
77
78 =cut
79
80 1;