Hi all

I would like to now what is the better pattern to do what I need. I try to
reduce the problem to a minimum, let me explain it step by step.

I have an interface Role like:

    package Likeable;
    use Moose::Role;

    requires 'likers';
    requires 'do_like';

After this, I need 2 Abstract Roles that semi-implement the previous
interface (in this case they implement all):

{
    package Likeable::OnSelf;
    use Moose::Role;

    with 'Likeable';

    has 'likers' => ( is => 'rw', isa => 'ArrayRef' );
    sub do_like { }
}

{
    package Likeable::OnParent;
    use Moose::Role;

    with 'Likeable';

    requires 'parent';

    sub likers { shift->parent->likers(@_) }
    sub do_like { shift->parent->do_like(@_) }
}

and later I need this code to compile

{
    package OBJ::OnSelf;
    use Moose;
    with 'Likeable::OnSelf';
}

{
    package OBJ::OnParent;
    use Moose;
    with 'Likeable::OnParent';
    has 'parent' => ( is => 'rw', isa => 'Obj' );
}

foreach my $obj (OBJ::OnSelf->new, OBJ::OnParent->new(parent =>
OBJ::OnSelf->new)) {
    if ( $obj->does('Likeable') ) {
        $obj->do_like
    }
}

the problem seems to me that is that I'm trying to do derivation on the
Moose::Role, but I have no ideia how to solve the problem correctly. May I
have your suggestions?

Best Regards
MArcos Rebelo

-- 
Marcos Rebelo
http://www.oleber.com/
Webmaster of http://perl5notebook.oleber.com

Reply via email to