On Thu, Apr 23, 2009 at 02:43:37PM +0100, Mark Morgan wrote:
> Based on the above, the adding of the attributes should be done for
> the entire class once, when the role is first used.  I don't like
> having to wrap constructor creation  to handle this, better that there
> should be an on-role-included hook that could be tied into.  Does such
> exist?  I've not seen anything documented for this type of behaviour.

No, and it usually means you're doing something wrong.  Adding new attributes
to a *class* when you create an *object* definitely fits.  Use
MooseX::Role::Parameterized.

  package DoesBooleanFilter;

  use MooseX::Role::Parameterized;

  parameter boolean_filters => (isa => 'ArrayRef[Str]', required => 1);

  role {
    my $p = shift;
    for my $filter (@{ $p->boolean_filters }) {
      has $filter => (
        is => 'ro',
        predicate => "has_$filter",
      );
    }
  };

  package SomeClass;

  use Moose;
  with 'DoesBooleanFilter' => { boolean_filters => [ qw(hello goodbye) ] };

hdp.

Reply via email to