develooper Front page | perl.moose | Postings from November 2014

RE: nested roles are badly limited

Thread Previous
From:
John Macdonald
Date:
November 22, 2014 13:53
Subject:
RE: nested roles are badly limited
Message ID:
01EF6156B387B14E8278ECC376793BE18F54CCC6@exmb2.ad.oicr.on.ca
Yes, that was one of my three examples.

Doing it that way means there are two problems:

1. ARole cannot encapsulate the entire interface - every consumer of ARole has to explicitly consume ARole and BRole.  Not only that, every consumer of ARole has to consume them in the right order - they have to support the internal implementation detail of ARole in two different ways that a fully encapsulated interface would hide completely.  Suppose ARole is updated to use an alternate BPlusRole for its needs - now you have to find every consumer of ARole and change how they load ARole. 

2. Additionally, every consumes has to consume ARole and BRole in two separate "with" statements - losing the cross-checking that with provides (for conflicting method/attribute names).

John Macdonald
Software Engineer

Ontario Institute for Cancer Research
MaRS Centre

661 University Avenue

Suite 510
Toronto, Ontario

Canada M5G 0A3


Tel:

Email: John.Macdonald@oicr.on.ca

Toll-free: 1-866-678-6427
Twitter: @OICR_news


www.oicr.on.ca

This message and any attachments may contain confidential and/or privileged information for the sole use of the intended recipient. Any review or distribution by anyone other than the person for whom it was originally intended is strictly prohibited. If you have received this message in error, please contact the sender and delete all copies. Opinions, conclusions or other information contained in this message may not be that of the organization.

________________________________________
From: moose@hidden-primary.net [moose@hidden-primary.net]
Sent: November 22, 2014 5:42 AM
To: moose@perl.org
Subject: Re: nested roles are badly limited

Hej John,

Am 21.11.2014 um 22:32 schrieb John Macdonald:
> ==== cat test1.pl
> package BRole;
> use Moose::Role;
>
> requires 'b';
>
> package ARole;
> use Moose::Role;
>
> has 'b' => ( is => 'ro', isa => 'Scalar' );
>
> package main;
> use Moose;
> with 'ARole', 'BRole';
> ====

just change it to this:

package BRole;
use Moose::Role;

requires 'b';

package ARole;
use Moose::Role;

has 'b' => (is => 'ro', isa => 'Scalar');

package main;
use Moose;
with 'ARole';
with 'BRole';

And you're done.

Kind regards

--
Marco

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About