Subject: | An incompatibility with Moose |
Date: | Thu, 08 Sep 2016 17:24:13 +0300 |
To: | bug-Moo [...] rt.cpan.org |
From: | Victor Porton <porton [...] narod.ru> |
An incompatibility of Moo with Moose:
From
http://perlguru.com/gforum.cgi?post=83459;sb=post_latest_reply;so=ASC;forum_view=forum_view_collapsed;;page=unread#unread
The following Perl code works with Moose but does not work (throws an exceptions) with Moo.
#!/usr/bin/perl
package X;
use Moo;
my $BusinessClass = "X";
my $Key = 'zz';
no strict 'refs';
*{"${BusinessClass}::access_$Key"} = sub { "Modified $Key" };
has $Key => ( is => 'rw',
required => 0,
accessor => { $Key => \&{"${BusinessClass}::access_$Key"} },
# predicate => { "has_$Key",\&{"${BusinessClass}::access2_$Key"} },
);
my $obj = X->new;
print $obj->zz, "\n";
My real-life problem is how to generate classes whose fields are accessed through custom accessors.
With Moose it can be accomplished by code like the above. But how to do this with Moo?
Can we make Moo compatible with Moose about this issue?