On Fri, Jan 28, 2011 at 9:35 PM, Karen Etheridge <[email protected]> wrote:
> On Fri, Jan 28, 2011 at 09:29:04PM +0100, Zbigniew Lukasiak wrote:
>> Are there any sane options for building Moose::Roles out of Non Moose
>> classes?
>>
>> Or maybe it is trivial?
>
> The thing about roles is they aren't instantiated, so you can't really do:
>
> package MyApp::Role::Foo;
>
> use base 'Some::Other::Class';
> use Moose::Role;
>
> ...because there is no way to call up the inheritance tree to get at
> methods in Some::Other::Class. However, if you imported functions from
> that class into your role, you can make them available in your role just
> the same as if you had implemented them into your role itself.
>
> Perhaps can you describe an example of what you want to do?
Well - that's what I was thinking, but:
use strict;
use warnings;
{
package Aa;
use Exporter 'import';
our @EXPORT_OK = qw(foo);
sub foo{
print "foooooooooo\n";
}
}
{
package Bb;
use Moose::Role;
Aa->import( 'foo' );
sub baz {
foo(shift);
}
sub bar {
print "baaaaaaaaaaar\n";
}
}
{
package Cc;
use Moose;
with 'Bb';
}
my $c = Cc->new();
$c->bar;
$c->baz;
$c->foo;
prints:
baaaaaaaaaaar
foooooooooo
Can't locate object method "foo" via package "Cc" at a.pl line 37.
So there is something missing, foo is not recognized as a method.
Z.