use Scalar::Util 'blessed';
use Sub::Exporter;
-our $VERSION = '0.24';
+our $VERSION = '0.50';
our $AUTHORITY = 'cpan:STEVAN';
## --------------------------------------------------------
no strict 'refs';
foreach my $constraint (keys %{$REGISTRY->type_constraints}) {
my $tc = $REGISTRY->get_type_constraint($constraint)->_compiled_type_constraint;
- *{"${pkg}::${constraint}"} = sub { $tc->($_[0]) ? 1 : undef };
+ *{"${pkg}::${constraint}"} = sub { $tc->($_[0]) ? 1 : undef }; # the undef is for compat
}
}
my $valid_chars = qr{[\w:]};
my $type_atom = qr{ $valid_chars+ };
+ my $any;
+
my $type = qr{ $valid_chars+ (?: \[ (??{$any}) \] )? }x;
my $type_capture_parts = qr{ ($valid_chars+) (?: \[ ((??{$any})) \] )? }x;
my $type_with_parameter = qr{ $valid_chars+ \[ (??{$any}) \] }x;
my $op_union = qr{ \s* \| \s* }x;
my $union = qr{ $type (?: $op_union $type )+ }x;
- our $any = qr{ $type | $union }x;
+ $any = qr{ $type | $union }x;
sub _parse_parameterized_type_constraint {
+ { no warnings 'void'; $any; } # force capture of interpolated lexical
$_[0] =~ m{ $type_capture_parts }x;
return ($1, $2);
}
sub _detect_parameterized_type_constraint {
+ { no warnings 'void'; $any; } # force capture of interpolated lexical
$_[0] =~ m{ ^ $type_with_parameter $ }x;
}
sub _parse_type_constraint_union {
+ { no warnings 'void'; $any; } # force capture of interpolated lexical
my $given = shift;
my @rv;
while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
}
sub _detect_type_constraint_union {
+ { no warnings 'void'; $any; } # force capture of interpolated lexical
$_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
}
}
=> 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 ...