} else {
$accessor .= $value.';';
}
- $accessor .= 'local $_ = $val;';
$accessor .= '
- unless ($constraint->()) {
- $attribute->verify_type_constraint_error($name, $_, $attribute->type_constraint);
+ unless ($constraint->($val)) {
+ $attribute->verify_type_constraint_error($name, $val, $attribute->type_constraint);
}' . "\n";
$value = '$val';
}
}
if ($trigger) {
- $accessor .= '$trigger->('.$self.', '.$value.', $attribute);' . "\n";
+ $accessor .= '$trigger->('.$self.', '.$value.');' . "\n";
}
$accessor .= "}\n";
return \%method_map;
}
-our $optimized_constraints;
+my $optimized_constraints;
sub _build_type_constraint {
my $spec = shift;
- local $optimized_constraints ||= Mouse::Util::TypeConstraints->optimized_constraints;
+ $optimized_constraints ||= Mouse::Util::TypeConstraints->optimized_constraints;
my $code;
if ($spec =~ /^([^\[]+)\[(.+)\]$/) {
# parameterized
} else {
Carp::confess("Support for parameterized types other than ArrayRef or HashRef is not implemented yet");
}
+ $optimized_constraints->{$spec} = $code;
} else {
$code = $optimized_constraints->{ $spec };
if (! $code) {
- $code = sub { Scalar::Util::blessed($_) && $_->isa($spec) };
+ $code = sub { Scalar::Util::blessed($_[0]) && $_[0]->isa($spec) };
$optimized_constraints->{$spec} = $code;
}
}
if exists $args{coerce};
if (exists $args{isa}) {
- warn "Got isa => $args{isa}, but Mouse does not yet support parameterized types for containers other than ArrayRef and HashRef (rt.cpan.org #39795)"
+ confess "Got isa => $args{isa}, but Mouse does not yet support parameterized types for containers other than ArrayRef and HashRef (rt.cpan.org #39795)"
if $args{isa} =~ /^([^\[]+)\[.+\]$/ &&
$1 ne 'ArrayRef' &&
$1 ne 'HashRef';
_build_type_constraint($_)
} @type_constraints;
$code = sub {
+ local $_ = $_[0];
for my $code (@code_list) {
- return 1 if $code->();
+ return 1 if $code->($_);
}
return 0;
};
sub verify_type_constraint_error {
my($self, $name, $value, $type) = @_;
$type = ref($type) eq 'ARRAY' ? join '|', @{ $type } : $type;
- my $display = defined($_) ? overload::StrVal($_) : 'undef';
+ my $display = defined($value) ? overload::StrVal($value) : 'undef';
Carp::confess("Attribute ($name) does not pass the type constraint because: Validation failed for \'$type\' failed with value $display");
}