54726460e1d50af8462e543a553751414bb6a40a
[gitmo/MooseX-Types.git] / lib / MooseX / Types / TypeDecorator.pm
1 package MooseX::Types::TypeDecorator;
2
3 use strict;
4 use warnings;
5
6 use overload(
7     '""' => sub {
8         shift->type_constraint->name;  
9     },
10 );
11
12 =head1 NAME
13
14 MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
15
16 =head1 DESCRIPTION
17
18 This is a decorator object that contains an underlying type constraint.  We use
19 this to control access to the type constraint and to add some features.
20
21 =head1 METHODS
22
23 This class defines the following methods.
24
25 =head2 new
26
27 Old school instantiation
28
29 =cut
30
31 sub new {
32     my ($class, %args) = @_;
33     return bless \%args, $class;
34 }
35
36 =head type_constraint ($type_constraint)
37
38 Set/Get the type_constraint
39
40 =cut
41
42 sub type_constraint {
43     my $self = shift @_;
44     if(my $tc = shift @_) {
45         $self->{type_constraint} = $tc;
46     }
47     return $self->{type_constraint};
48 }
49
50 =head2 DESTROY
51
52 We might need it later
53
54 =cut
55
56 sub DESTROY {
57     return;
58 }
59
60 =head2 AUTOLOAD
61
62 Delegate to the decorator targe
63
64 =cut
65
66 sub AUTOLOAD
67 {
68     my ($method) = (our $AUTOLOAD =~ /([^:]+)$/);
69     return shift->type_constraint->$method(@_);
70 }
71
72 =head1 AUTHOR AND COPYRIGHT
73
74 John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>
75
76 =head1 LICENSE
77
78 This program is free software; you can redistribute it and/or modify
79 it under the same terms as perl itself.
80
81 =cut
82
83 1;