Extending an attribute with a trait

[email protected] ("Dan Harbin")
Newsgroups perl.moose
Message-ID <[email protected]>
Stevan, other Moose-people,

I'm having a problem using an attribute trait in a subclass.  If I
have an attribute in the superclass, then extend that attribute in the
subclass by adding a trait, it complains about the behavior I'm adding
with: Illegal inherited options => (foo).  Since I made "foo"
required, then I can't add the trait without it complaining: Attribute
(foo) is required.

The following code demonstrates this issue.  Is there a workaround?

-----------------------

package Demo::Meta::Attribute::Trait::Foo;
use Moose::Role;

has foo => (
    is => 'rw',
    isa => 'Str',
    required => 1,
);

package Moose::Meta::Attribute::Custom::Trait::Foo;
sub register_implementation { 'Demo::Meta::Attribute::Trait::Foo' }

package MyClass;
use Moose;

has 'one' => (
    is => 'rw',
    isa => 'Str',
    traits => [qw/Foo/],
    foo => 'bar',
);

has 'two' => (
    is => 'rw',
    isa => 'Str',
);

package MySubClass;
use Moose;
extends 'MyClass';

has '+two' => (
    traits => [qw/Foo/],
    foo => 'baz',
);

package main;
use strict;
use warnings;

my $o = MySubClass->new();

1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.