On Fri, Apr 24, 2009 at 05:02:35PM +0100, Mark Morgan wrote:
> A very limited functionality, which won't be extended any further.  It
> seems to me the ideal candidate for handling as parameterized roles,
> as described earlier in the thread, in order to get common behaviour
> out of an oft-repeated idiom.

Getting "common behavior out of an oft-repeated idiom" is just refactoring,
generically, not something specific to parameterized roles.

The fact that you won't extend it any further makes me think that a simple
wrapper around has() is all you need.

  package YourApp::Attrs;

  use strict;
  use warnings;
  use Moose ();
  use Moose::Exporter;
  Moose::Exporter->setup_import_methods(
    with_caller => [ 'boolean_filter' ],
  );

  sub boolean_filter {
    my ($caller, $name, %options) = @_;
    Moose::Meta::Class->initialize($caller)->add_attribute(
      $name,
      is => 'ro',
      isa => 'Bool',
      predicate => "has_$name",
      %options,
    );
  }

  package YourApp::SomeModule;

  use Moose;
  use YourApp::Attrs;

  boolean_filter($_) for qw(hello goodbye);

See Moose::Exporter.  (MooseX::Attributes::Curried *almost* does this, but the
predicate isn't currently possible using it; Sartak, any good ideas?)

Anyway, your example was, I think, slimmed down to the point where I couldn't
see where you planned to use this, but if all you need is an accessor
generator, a role isn't the right concept.

hdp.

Reply via email to