Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 77406
Status: open
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: NMADDY1 [...] hfhs.org
Cc: CHOROBA [...] cpan.org
ribasushi [...] leporine.io
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Attribute delegated in one role does not satisfy requires of another role
Date: Thu, 24 May 2012 13:03:06 -0400
To: "'bug-Moose [...] rt.cpan.org'" <bug-Moose [...] rt.cpan.org>
From: "Maddy, Noel" <NMADDY1 [...] hfhs.org>
I have one role that provides a method by delegating it to an attribute, and another role that requires that method. When I try composing those two roles, Moose does not see the delegated method as satisfying the requires clause. I'm running Perl 5.14.2 under perlbrew on Fedora 16, with up-to-date CPAN, including Moose 2.0602. Here's a simplified example case, which gives the error: 'DelegatedYum|NeedsYum' requires the method 'yum' to be implemented by 'Composed' package HasYum; use Moose; has yum => ( is => 'ro', default => 37 ); package DelegatedYum; use Moose::Role; has has_yum => ( is => 'ro', default => sub { HasYum->new() }, handles => ['yum'] ); package NeedsYum; use Moose::Role; requires 'yum'; package Composed; use Moose; #with qw{ NeedsYum DelegatedYum }; with qw{ DelegatedYum NeedsYum }; Show quoted text
________________________________ CONFIDENTIALITY NOTICE: This email contains information from the sender that may be CONFIDENTIAL, LEGALLY PRIVILEGED, PROPRIETARY or otherwise protected from disclosure. This email is intended for use only by the person or entity to whom it is addressed. If you are not the intended recipient, any use, disclosure, copying, distribution, printing, or any action taken in reliance on the contents of this email, is strictly prohibited. If you received this email in error, please contact the sending party by reply email, delete the email from your computer system and shred any paper copies. Note to Patients: There are a number of risks you should consider before using e-mail to communicate with us. See our Privacy Policy and Henry Ford My Health at www.henryford.com for more detailed information. If you do not believe that our policy gives you the privacy and security protection you need, do not send e-mail or Internet communications to us.
The problem is that Moose::Meta::Role::Application:: {ToRole,RoleSummation} do not know what methods an attribute can provide. Moose::Meta::Attribute is capable of providing an accurate list of methods the attribute will provide (accessors, clearers, predicates, delegated methods, etc), but Moose::Meta::Role::Attribute is not. I've attached a patch which goes some way to solving this problem. It adds a method "_theoretically_associated_method_names" to Moose::Meta::Mixin::AttributeCore. This method returns a list of method names that will theoretically be provided by the attribute. It knows about all the Moose built-in stuff like clearers, predicates and built- ins, but third-party traits can obviously provide even more methods, and it won't know about them. The patch solves the reported issue, and gets seven of Moose's TODO tests passing. The patch doesn't modify the behaviour of Moose::Meta::Role::has_method. Perhaps it should?
Subject: Moose-theoretically_associated_method_names.diff

Message body is not shown because it is too large.

It's been two years. Could someone knowledgeable please review the patch?
On 2014-05-21 18:11:07, DAGOLDEN wrote: Show quoted text
> It's been two years. Could someone knowledgeable please review the patch?
BTW this is https://github.com/moose/Moose/pull/19 -- which does need a bit of updating for the changes to exceptions, but shouldn't need substantial revisions.
On 2014-05-21 20:11:07, DAGOLDEN wrote: Show quoted text
> It's been two years. Could someone knowledgeable please review the patch?
Well, now it's been four years. I did review the PR. Basically, it's not the right approach, unfortunately.
Interestingly, if you change use Moose::Role to use Moo::Role in DelegatedYum, it starts to work.