while (my ($name, $code) = each %builtins) {
$TYPE{$name} = Mouse::Meta::TypeConstraint->new(
- name => $name,
- _compiled_type_constraint => $code,
- package_defined_in => __PACKAGE__,
+ name => $name,
+ optimized => $code,
);
}
. "$existing->{package_defined_in} and cannot be created again in $package_defined_in");
}
- $args{constraint} = delete($args{where})
- if exists $args{where};
- $args{_compiled_type_constraint} = delete $args{optimized_as}
- if exists $args{optimized_as};
+ $args{constraint} = delete($args{where}) if exists $args{where};
+ $args{optimized} = delete $args{optimized_as} if exists $args{optimized_as};
my $constraint;
if($mode eq 'subtype'){
- my $parent = exists($args{as}) ? delete($args{as}) : delete($args{name});
+ my $parent = delete($args{as})
+ or confess('A subtype cannot consist solely of a name, it must have a parent');
- $parent = find_or_create_isa_type_constraint($parent);
- $constraint = $parent->create_child_type(%args);
+ $constraint = find_or_create_isa_type_constraint($parent)->create_child_type(%args);
}
else{
$constraint = Mouse::Meta::TypeConstraint->new(%args);
my $check;
my $type;
- if($meta && $meta->isa('Mouse::Meta::Role')){
+ if($meta->isa('Mouse::Meta::Role')){
$check = sub{
return blessed($_[0]) && $_[0]->does($spec);
};
warn "#CREATE a $type type for $spec\n" if _DEBUG;
return $TYPE{$spec} = Mouse::Meta::TypeConstraint->new(
- name => $spec,
- _compiled_type_constraint => $check,
+ name => $spec,
+ optimized => $check,
- type => $type,
+ type => $type,
);
}
$TYPE{ArrayRef}{constraint_generator} = sub {
my($type_parameter) = @_;
- my $check = $type_parameter->{_compiled_type_constraint};
+ my $check = $type_parameter->_compiled_type_constraint;
return sub{
foreach my $value (@{$_}) {
};
$TYPE{HashRef}{constraint_generator} = sub {
my($type_parameter) = @_;
- my $check = $type_parameter->{_compiled_type_constraint};
+ my $check = $type_parameter->_compiled_type_constraint;
return sub{
foreach my $value(values %{$_}){
# 'Maybe' type accepts 'Any', so it requires parameters
$TYPE{Maybe}{constraint_generator} = sub {
my($type_parameter) = @_;
- my $check = $type_parameter->{_compiled_type_constraint};
+ my $check = $type_parameter->_compiled_type_constraint;
return sub{
return !defined($_) || $check->($_);
}
}
sub _find_or_create_union_type{
- my @types = map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_;
+ my @types = map{ $_->{type_constraints} ? @{$_->{type_constraints}} : $_ } @_;
my $name = join '|', map{ $_->name } @types;
$TYPE{$name} ||= do{
warn "# CREATE a Union type for ", Mouse::Util::english_list(@types),"\n" if _DEBUG;
- my @checks = map{ $_->{_compiled_type_constraint} } @types;
- my $check = sub{
- foreach my $c(@checks){
- return 1 if $c->($_[0]);
- }
- return 0;
- };
-
return Mouse::Meta::TypeConstraint->new(
- name => $name,
- _compiled_type_constraint => $check,
- type_constraints => \@types,
+ name => $name,
+ type_constraints => \@types,
- type => 'Union',
+ type => 'Union',
);
};
}
my $char = substr($spec, $i, 1);
if($char eq '['){
- my $base = _find_or_create_regular_type( substr($spec, $start, $i - $start))
+ my $base = _find_or_create_regular_type( substr($spec, $start, $i - $start) )
or return;
($i, $subtype) = _parse_type($spec, $i+1)
last;
}
elsif($char eq '|'){
- my $type = _find_or_create_regular_type( substr($spec, $start, $i - $start))
- or return;
+ my $type = _find_or_create_regular_type( substr($spec, $start, $i - $start) );
+
+ if(!defined $type){
+ # XXX: Mouse creates a new class type, but Moose does not.
+ $type = class_type( substr($spec, $start, $i - $start) );
+ }
push @list, $type;
=head1 METHODS
-=head2 optimized_constraints -> HashRef[CODE]
+=head2 C<< list_all_builtin_type_constraints -> (Names) >>
+
+Returns the names of builtin type constraints.
+
+=head2 C<< list_all_type_constraints -> (Names) >>
-Returns the simple type constraints that Mouse understands.
+Returns the names of all the type constraints.
=head1 FUNCTIONS