use strict;
use warnings;
+
use Carp::Clan qw( ^MooseX::Types );
use Moose::Util::TypeConstraints ();
use Moose::Meta::TypeConstraint::Union;
use overload(
'""' => sub {
- return shift->__type_constraint->name;
+ my $self = shift @_;
+ if(blessed $self) {
+ return $self->__type_constraint->name;
+ } else {
+ return "$self";
+ }
},
'|' => sub {
);
-
=head1 NAME
MooseX::Types::TypeDecorator - More flexible access to a Type Constraint
=cut
sub __type_constraint {
- my $self = shift @_;
-
+ my $self = shift @_;
if(blessed $self) {
if(defined(my $tc = shift @_)) {
$self->{__type_constraint} = $tc;
sub isa {
my ($self, $target) = @_;
if(defined $target) {
- return $self->__type_constraint->isa($target);
+ if(blessed $self) {
+ return $self->__type_constraint->isa($target);
+ } else {
+ return;
+ }
} else {
return;
}
sub can {
my ($self, $target) = @_;
if(defined $target) {
- return $self->__type_constraint->can($target);
+ if(blessed $self) {
+ return $self->__type_constraint->can($target);
+ } else {
+ return;
+ }
} else {
return;
}
}
+=head2 meta
+
+have meta examine the underlying type constraints
+
+=cut
+
+sub meta {
+ my $self = shift @_;
+ if(blessed $self) {
+ return $self->__type_constraint->meta;
+ }
+}
+
+
=head2 DESTROY
We might need it later
=cut
sub AUTOLOAD {
+
my ($self, @args) = @_;
my ($method) = (our $AUTOLOAD =~ /([^:]+)$/);
- if($self->__type_constraint->can($method)) {
- return $self->__type_constraint->$method(@args);
+
+ ## We delegate with this method in an attempt to support a value of
+ ## __type_constraint which is also AUTOLOADing, in particular the class
+ ## MooseX::Types::UndefinedType which AUTOLOADs during autovivication.
+
+ my $return;
+
+ eval {
+ $return = $self->__type_constraint->$method(@args);
+ }; if($@) {
+ croak $@;
} else {
- croak "Method '$method' is not supported for ". ref($self->__type_constraint);
+ return $return;
}
}