On Wed, May 19, 2010 at 9:15 PM, Kate Yoak <k...@yoak.com> wrote:
>>
>> after has_a => sub {
>>    my ($class, $method_name) = (shift, shift);
>>
>>    my $method = Moose::Meta::Method->wrap(
>>        associated_metaclass => $class->meta,
>>        package_name => $class,
>>        name => $method_name,
>>        body => $class->meta->get_all_package_symbols('CODE')->{$method_name},
>>    );
>>
>>    $class->meta->add_method($method_name => $method);
>> };
>>
>
> OK, that's neat.  Perhaps even neater than the Sub::Name suggestion.  I'll 
> add it to my list to investigate.  This problem actually screams for a 
> MooseX::ImportGlobs kind of a module.  It feels like one ought to be able to 
> dig around, find all the unnamed globs and import them into meta with a 
> single line of code.

I've refactored MooseX::MarkAsMethods a bit, to provide
mark_as_method() via the metaclass. It'll handle the messy parts of
marking something as a method (in a fashion hopefully close to
correct); e.g.

__PACKAGE__->meta->mark_as_method('foo');

Note the only bits MX::MAM automatically tries to mark as methods are
overloads.  We don't tinker with the method heuristic aside from this.

In writing (a very few intial) tests for this, I found that CMOP/Moose
pick up on what's a method and what's not in all but a few situations:

* the method is an overload; or
* the method was added via typeglob assignment after class composition
has completed.

That's not a comprehensive list :)

I'd be very careful about actually using mark_as_methods(), however:
if something is not being picked up as a method, chances are very
likely that there's a good reason for it.

                   -Chris
-- 
Chris Weyl
Ex astris, scientia

Reply via email to