Subject: | MooseX::ClassAttribute does not play well with MooseX::Role::Parameterized |
It does not appear to be possible to manipulate class attributes from
within a parameterized role. The error is:
Attribute (genitor) is required at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Class/MOP/Class.pm line
364
The below example includes two different uses of a class attribute from
within a parameterized role, each of which give the same error (above):
#!/usr/bin/perl
use strict;
use warnings;
{
package Role;
use MooseX::Role::Parameterized;
use MooseX::ClassAttribute;
parameter foo => ( is => 'ro', isa => 'Str' );
role {
my $params = shift;
my %args = @_;
# example 1
class_has role_attr1 => (
is => 'ro', isa => 'Str',
default => $params->foo,
);
# example 2
my $meta = $args{consumer};
$meta->add_class_attribute('role_attr2', isa => 'Str');
};
}
{
package Foo;
use Moose;
with 'Role' => { foo => 'bar' };
}
package main;
print "compilation successful!\n";