));
__PACKAGE__->meta->add_attribute('inlined' => (
+ init_arg => 'inlined',
accessor => 'inlined',
- predicate => 'has_inlined_type_constraint',
+ predicate => '_has_inlined_type_constraint',
));
sub parents {
}
}
+sub has_inlined_type_constraint {
+ my $self = shift;
+
+ if ( $self->has_parent && $self->constraint eq $null_constraint ) {
+ return $self->parent->has_inlined_type_constraint;
+ }
+
+ return $self->_has_inlined_type_constraint;
+}
+
sub _inline_check {
my $self = shift;
Moose->throw_error( 'Cannot inline a type constraint check for ' . $self->name );
}
+ if ( $self->has_parent && $self->constraint eq $null_constraint ) {
+ return $self->parent->_inline_check(@_);
+ }
+
return $self->inlined->( $self, @_ );
}
my $self = $class->_new( \%args );
- $self->_create_hand_optimized_type_constraint;
$self->compile_type_constraint();
return $self;
}
-sub _create_hand_optimized_type_constraint {
- my $self = shift;
- my $class = $self->class;
- $self->hand_optimized_type_constraint(
- sub {
- blessed( $_[0] ) && $_[0]->isa($class)
- }
- );
-}
-
sub parents {
my $self = shift;
return (
};
}
-sub _compile_hand_optimized_type_constraint {
- my $self = shift;
-
- my @methods = @{ $self->methods };
-
- sub {
- my $obj = shift;
-
- return blessed($obj)
- && blessed($obj) ne 'Regexp'
- && all { $obj->can($_) } @methods;
- };
-}
-
sub create_child_type {
my ($self, @args) = @_;
return Moose::Meta::TypeConstraint->new(@args, parent => $self);
return sub { exists $values{$_[0]} };
}
-sub _compile_hand_optimized_type_constraint {
- my $self = shift;
-
- my %values = map { $_ => undef } @{ $self->values };
-
- sub { defined($_[0]) && !ref($_[0]) && exists $values{$_[0]} };
-}
-
sub create_child_type {
my ($self, @args) = @_;
return Moose::Meta::TypeConstraint->new(@args, parent => $self);
subtype 'ArrayOfNotInlinable',
as 'ArrayRef[NotInlinable]';
-
{
- local $TODO = 'A subtype of a Parameterized type should not be a Parameterizable type';
-
my $aofi = Moose::Util::TypeConstraints::find_or_create_type_constraint(
'ArrayOfInlinable');
$aofi->has_inlined_type_constraint,
'ArrayOfInlinable returns true for has_inlined_type_constraint'
);
+
+ is(
+ $aofi->_inline_check('$foo'),
+ q{ref $foo eq 'ARRAY' && &List::MoreUtils::all( sub { defined $_ && ! ref $_ && $_ !~ /Q/ }, @{$foo} )},
+ 'got expected inline code for ArrayOfInlinable constraint'
+ );
+
+ my $aofni = Moose::Util::TypeConstraints::find_or_create_type_constraint(
+ 'ArrayOfNotInlinable');
+
+ ok(
+ !$aofni->has_inlined_type_constraint,
+ 'ArrayOfNotInlinable returns false for has_inlined_type_constraint'
+ );
}
{