use warnings;
use Carp 'confess';
-use Scalar::Util 'blessed', 'reftype';
+use Scalar::Util 'blessed';
use Sub::Exporter;
-our $VERSION = '0.22';
+our $VERSION = '0.50';
our $AUTHORITY = 'cpan:STEVAN';
## --------------------------------------------------------
# subtype(MyNumbers => as Num); # now MyNumbers is the same as Num
# ... yeah I know it's ugly code
# - SL
- unshift @_ => undef if scalar @_ <= 2 && (reftype($_[1]) || '') eq 'CODE';
+ unshift @_ => undef if scalar @_ <= 2 && ('CODE' eq ref($_[1]));
goto &_create_type_constraint;
}
my $class = "Moose::Meta::TypeConstraint";
# FIXME should probably not be a special case
- # FIXME also support metaclass/traits in TCs
if ( defined $parent and $parent = find_or_parse_type_constraint($parent) ) {
- $class = "Moose::Meta::TypeConstraint::Parameterizable" if $parent->isa("Moose::Meta::TypeConstraint::Parameterizable");
+ $class = "Moose::Meta::TypeConstraint::Parameterizable"
+ if $parent->isa("Moose::Meta::TypeConstraint::Parameterizable");
}
my $constraint = $class->new(
=> optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Role;
my $_class_name_checker = sub {
- return if ref($_[0]);
- return unless defined($_[0]) && length($_[0]);
-
- # walk the symbol table tree to avoid autovififying
- # \*{${main::}{"Foo::"}} == \*main::Foo::
-
- my $pack = \*::;
- foreach my $part (split('::', $_[0])) {
- return unless exists ${$$pack}{"${part}::"};
- $pack = \*{${$$pack}{"${part}::"}};
- }
-
- # check for $VERSION or @ISA
- return 1 if exists ${$$pack}{VERSION}
- && defined *{${$$pack}{VERSION}}{SCALAR};
- return 1 if exists ${$$pack}{ISA}
- && defined *{${$$pack}{ISA}}{ARRAY};
-
- # check for any method
- foreach ( keys %{$$pack} ) {
- next if substr($_, -2, 2) eq '::';
- return 1 if defined *{${$$pack}{$_}}{CODE};
- }
-
- # fail
- return;
};
subtype 'ClassName'
=> as 'Str'
- => $_class_name_checker # where ...
- => { optimize => $_class_name_checker };
+ => where { Class::MOP::is_class_loaded($_) }
+ => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::ClassName;
## --------------------------------------------------------
# parameterizable types ...