1 package MooseX::Types::TypeDecorator;
6 use Carp::Clan qw( ^MooseX::Types );
7 use Moose::Util::TypeConstraints;
8 use Moose::Meta::TypeConstraint::Union;
12 shift->type_constraint->name;
15 my @tc = grep {ref $_} @_;
16 my $union = Moose::Meta::TypeConstraint::Union->new(type_constraints=>\@tc);
17 return Moose::Util::TypeConstraints::register_type_constraint($union);
23 MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
27 This is a decorator object that contains an underlying type constraint. We use
28 this to control access to the type constraint and to add some features.
32 This class defines the following methods.
36 Old school instantiation
41 my ($class, %args) = @_;
43 $args{type_constraint} && ref($args{type_constraint}) &&
44 ($args{type_constraint}->isa('Moose::Meta::TypeConstraint') ||
45 $args{type_constraint}->isa('MooseX::Types::UndefinedType'))
47 return bless \%args, $class;
49 croak "The argument 'type_constraint' is not valid.";
54 =head type_constraint ($type_constraint)
56 Set/Get the type_constraint.
62 if(defined(my $tc = shift @_)) {
63 $self->{type_constraint} = $tc;
65 return $self->{type_constraint};
70 handle $self->isa since AUTOLOAD can't.
75 my ($self, $target) = @_;
77 my $isa = $self->type_constraint->isa($target);
86 handle $self->can since AUTOLOAD can't.
91 my ($self, $target) = @_;
93 my $can = $self->type_constraint->can($target);
102 We might need it later
112 Delegate to the decorator targe
117 my ($method) = (our $AUTOLOAD =~ /([^:]+)$/);
118 return shift->type_constraint->$method(@_);
121 =head1 AUTHOR AND COPYRIGHT
123 John Napiorkowski (jnapiorkowski) <jjnapiork@cpan.org>
127 This program is free software; you can redistribute it and/or modify
128 it under the same terms as perl itself.