Ovid,
Honestly, I think this is more a bug in Memoize. It is destroying
information that can easily be replaced by Sub::Name.
On May 13, 2009, at 10:24 AM, Ovid wrote:
In short, you can't:
#!/usr/bin/env perl -l
{
package My::Role;
use Moose::Role;
use Memoize;
memoize('foo');
sub foo { __PACKAGE__ }
}
{
package My::Class;
use Moose;
with 'My::Role';
}
print My::Class->foo;
If you comment out the 'memoize(foo)' line, it works fine. This is
because methods/subs not defined in the role itself will not be
composed into your class. memoize() rewrites the method and thus
the 'foo' method is defined in the Memoize module.
This clearly is not a bug, but it's a surprising behavior.
Not really, we are very clear about the fact we distinguish between
methods created within the package and those created outside of the
package.
I'd hate to have to put the memoize(foo) call into all classes which
consume the role. Thus, it would be nice if there was either a
special case (yuck) for Memoize or that Moose provides something
similar.
No way, I am not going to start down the slippery slope of putting in
special cases for $random modules. Down this road is nothing but pain,
anger, hatred and the dark side!
Using Moose::Exporter you should be able to add your own memoize sugar
wrapper that can apply the Sub::Name magic to get this working
correctly. Hop on IRC and I am sure people will help you through some
of the more thorny bits.
- Stevan
Side note: for Moose::Manual::Role, 'brake' is misspelled as 'break'
in the Car example. I know why it was done this way, but a better
example would be nice :)
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