X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FTypeDecorator.pm;h=ebe0f5d5304c0dfec57fb4f5cec6f9ae2c8637d8;hb=c1260541fc8dffb9e348c5fdd8b6d3c99b247677;hp=46a3fbd757f5a280c844ee58ba49dc1b6194ea46;hpb=077ac262426e5f48cfe70fd1711ccd27971fab44;p=gitmo%2FMooseX-Types.git diff --git a/lib/MooseX/Types/TypeDecorator.pm b/lib/MooseX/Types/TypeDecorator.pm index 46a3fbd..ebe0f5d 100644 --- a/lib/MooseX/Types/TypeDecorator.pm +++ b/lib/MooseX/Types/TypeDecorator.pm @@ -3,6 +3,7 @@ package MooseX::Types::TypeDecorator; use strict; use warnings; + use Carp::Clan qw( ^MooseX::Types ); use Moose::Util::TypeConstraints (); use Moose::Meta::TypeConstraint::Union; @@ -10,7 +11,12 @@ use Scalar::Util qw(blessed); use overload( '""' => sub { - return shift->__type_constraint->name; + my $self = shift @_; + if(blessed $self) { + return $self->__type_constraint->name; + } else { + return "$self"; + } }, '|' => sub { @@ -26,7 +32,6 @@ use overload( ); - =head1 NAME MooseX::Types::TypeDecorator - More flexible access to a Type Constraint @@ -74,8 +79,7 @@ Set/Get the type_constraint. =cut sub __type_constraint { - my $self = shift @_; - + my $self = shift @_; if(blessed $self) { if(defined(my $tc = shift @_)) { $self->{__type_constraint} = $tc; @@ -95,7 +99,11 @@ handle $self->isa since AUTOLOAD can't. 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; } @@ -110,12 +118,30 @@ handle $self->can since AUTOLOAD can't. 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