Subject: | Moose::Meta::Attribute::Native::Trait::Hash breaks when using "clear, delete" with custom type |
Date: | Sat, 25 Nov 2017 10:09:49 +0100 |
To: | bug-Moose [...] rt.cpan.org |
From: | Ralf Bartel <bartel.rj [...] gmail.com> |
perl 5, version 22, subversion 1 (v5.22.1) built for
x86_64-linux-gnu-thread-multi
Linux Sun 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017
x86_64 x86_64 x86_64 GNU/Linux
Linux Sun 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017
x86_64 x86_64 x86_64 GNU/Linux
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
{
package Foo;
use Moose;
has 'bar' =>
( isa => 'Str', lazy => 1, is => 'rw', default => sub { 'bar' } );
no Moose;
__PACKAGE__->meta->make_immutable;
}
{
package Test;
use Moose;
use Moose::Util::TypeConstraints;
class_type 'TFoo' => { class => 'Foo' };
coerce 'TFoo' => from 'Str' => via { Foo->new( foo => $_ ) };
subtype 'TFooHash' => as 'HashRef[TFoo]';
coerce 'TFooHash' => from 'HashRef[Str]' => via {
my $h = $_;
return {
map { $_ => find_type_constraint('TFoo')->coerce( $h->{$_} ) }
keys %$h
};
};
has 'fooH' => (
traits => ['Hash'],
is => 'rw',
lazy => 1,
isa => 'TFooHash',
coerce => 1,
default => sub { { foo => 'bar' } },
handles => {
exists_in_fooHs => 'exists',
ids_in_fooHs => 'keys',
values_in_fooHs => 'values',
get_fooH => 'get',
set_fooH => 'set',
no_fooHs => 'is_empty',
fooH_pairs => 'kv',
num_fooHs => 'count',
clone_fooHs => 'shallow_clone',
# clear_fooHs => 'clear',
# remove_fooH => 'delete',
},
);
no Moose;
__PACKAGE__->meta->make_immutable;
}
my $test = Test->new;
my $clone = $test->clone_fooHs;
say $clone->{foo}->bar;
uncomment any of these "remove_fooH" or "clear_fooHs" and it will produce an
"Can't locate object method "_new_members" via package
"Moose::Meta::Class::__ANON__::SERIAL::#" at
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1/Moose/Meta/Method/Accessor/Native/Collection.pm
line 19"
error message
looks like a bug to me.
Thanks in advance for eventually fixing it.