On Tue, Aug 28, 2012 at 10:19:36AM -0700, Peter Shangov wrote: > Hi, > > MoooseX::Has::Options (https://metacpan.org/module/MooseX::Has::Options) adds > a different syntax for declaring Moose attribute options, i.e. instead of: > > has 'foo', is => 'ro', isa => 'Str', lazy_build => 1; > > it allows you to say: > > has 'foo', qw(:ro :lazy_build), isa => 'Str'; > > The current implementation is a little naive and works by directly replacing > the 'has' subroutine in the calling package. Instead I want to make this work > providing a new attribute metaclass that knows how to deal with the > column-option syntax. The problem is that Moose::has() checks that the > options list is even-sized, and will die with an odd number of column options. > > So which of the following imperfect approaches would you recommend that I > should take: > > 1. Replace the imported 'has' with a new one that does exactly the same but > without the list size check. This means that the custom 'has' will go out of > sync whenever the implementation of Moose::has() changes. > > 2. Apply an 'around' method modifier to Moose::has() that adds a dummy column > option if the options list is not even-sized, and make the attribute > metaclass handle it as a no-op. This means that the end will get to see this > dummy option (e.g. in stack traces) and possibly get confused. > > 3. Apply an 'around' method modifier to Moose::has() that does all the column > options pre-processing itself. This means not using an attribute metaclass at > all and is only marginally better than the original approach. > > Any ideas?
That check really doesn't belong in Moose::has - it should be done in _process_options in Class::MOP::Attribute. A patch to move that over would be quite appreciated. -doy
