predicate => '_has_inlined_type_constraint',
));
+__PACKAGE__->meta->add_attribute('inline_environment' => (
+ init_arg => 'inline_environment',
+ accessor => 'inline_environment',
+ default => sub { {} },
+));
+
sub parents {
my $self;
$self->parent;
if ( $self->has_inlined_type_constraint ) {
return eval_closure(
- source => 'sub { ' . $self->_inline_check('$_[0]') . ' }',
+ source => 'sub { ' . $self->_inline_check('$_[0]') . ' }',
+ environment => $self->inline_environment,
);
}
accessor => 'values',
));
-our %ENUMS;
-
my $inliner = sub {
my $self = shift;
my $val = shift;
- my $name = $self->name();
- $ENUMS{$name} ||= { map { $_ => 1 } @{ $self->values() } };
-
return 'defined(' . $val . ') '
. '&& !ref(' . $val . ') '
- . '&& $' . __PACKAGE__ . '::ENUMS{' . B::perlstring($name) . '}'
- . '{' . $val . '}';
+ . '&& $enums{' . $val . '}';
};
sub new {
my %values = map { $_ => 1 } @{ $args{values} };
$args{constraint} = sub { $values{ $_[0] } };
+ $args{inline_environment} = { '%enums' => \%values };
my $self = $class->_new(\%args);
if ( $type->has_inlined_type_constraint ) {
$inlined = eval_closure(
source => 'sub { ( ' . $type->_inline_check('$_[0]') . ' ) }',
+ environment => $type->inline_environment,
);
}