Subject: | transform_trait has side effect |
I have attached an example of this issue.
If I pass an arrayref to the new_with_traits constructor ( traits =>
$arrayref ) it is altered by the map statement (and transform_trait) on
line 36. This prevents me from reusing the arrayref in subsequent calls
to new_with_traits because it has already been transformed.
My suggested solution is to copy $args{traits} before the transformation
in order to prevent such side effects.
Subject: | demo.pl |
#!/usr/bin/env perl5.10
use feature 'say';
package My::Role::DoesFoo;
{
use Moose::Role;
has foo => ( is => 'ro', isa => 'Int', required => 1 );
}
package Class;
{
use Moose;
with 'MooseX::Traits';
has '+_trait_namespace' => ( default => 'My::Role' );
}
package main;
{
my $traits = [qw/DoesFoo/];
my $c1 = Class->new_with_traits( traits => $traits, foo => 41 ); # works
say $_ for @$traits; # WRONG: "My::Role::DoesFoo" - should be "DoesFoo"
# this time transforms My::Role::DoesFoo into My::Role::My::Role::DoesFoo
my $c2 = Class->new_with_traits( traits => $traits, foo => 42 ); # fails
my $c3 = Class->new_with_traits( traits => $traits, foo => 43 );
}