I have a first pass attempt at "with Some::Role => { includes => \...@methods
}" at:
http://github.com/Ovid/moose/tree/master
There are a few issues here and I didn't want to go much further without some
direction.
First, we have a few nasty variations of this:
Moose::Meta::Role::Application::ToInstance->new($self, $other,
@args)->apply($self, $other);
I needed to pass the $self and $other metaclasses to the constructor to ensure
I had proper names for error reporting. I thought to make them instance data
because this is happening in a couple of spots. That would collapse the above
code to something similar to this:
Moose::Meta::Role::Application::ToInstance->new($self, $other, @args)->apply;
It's still ugly as sin, though, and if someone else wants to take a gander,
that would be great.
Second: includes and excludes are mutually exclusive and throw an exception if
you try to use both at the same time. There are issues surrounding this. What
if your inclusion and exclusion lists are not exhaustive? What happens to the
methods not listed? What if they overlap? I could try to code for all of this,
but it seemed awkward.
Third: role methods not included in 'includes' are added to the required method
list. This allows a composition-time failure when you try to use a method a
role provides but it wasn't defined in the class or listed in the 'includes'
list.
Fourth: what happens in this case?
package My::Class;
use Moose;
with 'Some::Role' => { includes => 'foo' };
sub foo { ... }
You've attempted to include a method, but it won't be included because you've
already defined it. What's the proper behavior here?
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Tech blog - http://use.perl.org/~Ovid/journal/
Twitter - http://twitter.com/OvidPerl
Official Perl 6 Wiki - http://www.perlfoundation.org/perl6