1 package MooseX::Types::TypeDecorator;
6 use Carp::Clan qw( ^MooseX::Types );
7 use Moose::Util::TypeConstraints ();
8 use Moose::Meta::TypeConstraint::Union;
12 return shift->__type_constraint->name;
16 ## It's kind of ugly that we need to know about Union Types, but this
17 ## is needed for syntax compatibility. Maybe someday we'll all just do
20 my @tc = grep {ref $_} @_;
21 my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc);
22 return Moose::Util::TypeConstraints::register_type_constraint($union);
28 MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
32 This is a decorator object that contains an underlying type constraint. We use
33 this to control access to the type constraint and to add some features.
37 This class defines the following methods.
41 Old school instantiation
47 if(my $arg = shift @_) {
48 if(ref $arg && $arg->isa('Moose::Meta::TypeConstraint')) {
49 return bless {'__type_constraint'=>$arg}, $class;
50 } elsif(ref $arg && $arg->isa('MooseX::Types::UndefinedType')) {
51 ## stub in case we'll need to handle these types differently
52 return bless {'__type_constraint'=>$arg}, $class;
54 croak "Argument must be ->isa('Moose::Meta::TypeConstraint') or ->isa('MooseX::Types::UndefinedType')";
57 croak "This method [new] requires a single argument of 'arg'.";
61 =head __type_constraint ($type_constraint)
63 Set/Get the type_constraint.
67 sub __type_constraint {
69 if(defined(my $tc = shift @_)) {
70 $self->{__type_constraint} = $tc;
72 return $self->{__type_constraint};
77 handle $self->isa since AUTOLOAD can't.
82 my ($self, $target) = @_;
84 return $self->__type_constraint->isa($target);
92 handle $self->can since AUTOLOAD can't.
97 my ($self, $target) = @_;
99 return $self->__type_constraint->can($target);
107 We might need it later
117 Delegate to the decorator targe
122 my ($self, @args) = @_;
123 my ($method) = (our $AUTOLOAD =~ /([^:]+)$/);
124 if($self->__type_constraint->can($method)) {
125 return $self->__type_constraint->$method(@args);
127 croak "Method '$method' is not supported";
131 =head1 AUTHOR AND COPYRIGHT
133 John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>
137 This program is free software; you can redistribute it and/or modify
138 it under the same terms as perl itself.