Subject: | Array map/grep method allows to change value without constraint check |
Date: | Sun, 9 Oct 2016 01:53:31 +0200 |
To: | bug-Moose [...] rt.cpan.org |
From: | Branislav Zahradník <happy.barney [...] gmail.com> |
If code passed to native trait map/grep assigns value to $_, value is
stored but constraints are not verified.
Snippet:
package Foo;
has list => is => 'ro', isa => 'ArrayRef[Defined]', handles => { map =>
'map' };
Usage;
my $foo = Foo->new( list => [1 .. 10] );
$foo->map( sub { $_ = undef } );
Solution:
return 'map { local $_ = $_; $_[0]->() } @{ (' . $slot_access . ') }';
Best regards,
Branislav Zahradník