in reply to moose role that uses a class that does the role
I would guess that you really want to use requires in your role to require certain functionality of the consumer of your role (in this case Greeting) possibly combined with normal inheritance. For example:
package Hello; use Moose::Role; use namespace::autoclean; # Insist that someone who "with"s us, has a greet method requires "greet"; sub hello_world { my $self = shift; $self->greet("hello world\n"); } 1;
Greeting:
package Greeting; use Moose; use namespace::autoclean; with 'Hello'; sub greet { my ($self, @stuff) = @_; print @stuff; } __PACKAGE__->meta->make_immutable; 1;
Greeting2:
package Greeting2; use Moose; use namespace::autoclean; with 'Hello'; sub greet { my ($self, @stuff) = @_; print map uc($_), @stuff; } __PACKAGE__->meta->make_immutable; 1;
Greeting3 (uses the greet from Greeting):
package Greeting3; use Moose; use namespace::autoclean; extends 'Greeting'; # already "with" Hello __PACKAGE__->meta->make_immutable; 1;
Now your test script produces:
Greeting=HASH(0x2b411f8) does Hello hello world Greeting2=HASH(0x1a541f8) does Hello HELLO WORLD Greeting3=HASH(0x15c01f8) does Hello hello world
Update: Added script output. Also, I second tospo's suggestion to move all of the common functionality to the Hello role
Good Day,
Dean
|
|---|