Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 46842
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: rt.cpan [...] sartak.org
Requestors: jshirley+cpan [...] gmail.com
Cc:
AdminCc:

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



Subject: If a Role has "use Package::That::Consumes::Me", methods don't get applied
In latest Class::MOP/Moose, if a Role has uses a class that ends up consuming the role it doesn't get applied correctly. Please see the gist for an example and failing test: http://gist.github.com/127614 (As an aside, I spoke with Sartak on IRC. I will commit a failing test case for this but out of time now and didn't want to drop this)
I'm pretty sure I know why this is happening. If Role uses Package::That::Consumes::Me, that's usually at the top of the file, before any methods are defined. So Moose sees that the role is empty, since methods haven't had a chance to be defined yet. Both "use" and "sub" happen at compile time, remember. Changing this to "require Package::That::Consumes::Me" should fix it. I don't know how we can even detect this kind of thing in Moose. Shawn
On Sat Jul 25 12:44:48 2009, SARTAK wrote: Show quoted text
> I'm pretty sure I know why this is happening. > > If Role uses Package::That::Consumes::Me, that's usually at the top of > the file, before any methods are defined. So Moose sees that the role is > empty, since methods haven't had a chance to be defined yet. Both "use" > and "sub" happen at compile time, remember. > > Changing this to "require Package::That::Consumes::Me" should fix it. > > I don't know how we can even detect this kind of thing in Moose. > > Shawn
I think that it is best to throw a warning, but I'm not too sure of the internals of Moose. It seems that the scope of 'with' should be able to detect at some point what the direct dependencies are (I'm not sure if you can do this in Perl, but it seems like you should). I don't think that this behavior should be supported, but if there was a warning I'd be thrilled. It would have saved me a lot of puzzling refactor time :) -J
Subject: Re: [rt.cpan.org #46842] If a Role has "use Package::That::Consumes::Me", methods don't get applied
Date: Sun, 26 Jul 2009 18:07:45 +0100
To: bug-Moose [...] rt.cpan.org
From: Yuval Kogman <nuffin [...] cpan.org>
AFAICT, there's no real way to detect whether or not the role is fully composed or not, aside from guessing by looking at the stack and checking if one of the callers is it. That is indistinguishable from the correct behavior (require at the end). That said, this sounds to me like a case of code smell. You should probably just add a top level .pm file that loads all the relevant components, instead of defining mutually recursive modules (which are a bad idea in Perl anyway).
On Sun Jul 26 13:08:05 2009, NUFFIN wrote: Show quoted text
> AFAICT, there's no real way to detect whether or not the role is fully > composed or not, aside from guessing by looking at the stack and > checking if one of the callers is it. That is indistinguishable from > the correct behavior (require at the end). > > > That said, this sounds to me like a case of code smell. You should > probably just add a top level .pm file that loads all the relevant > components, instead of defining mutually recursive modules (which are > a bad idea in Perl anyway).
It is code smell. I just encountered this when I was refactoring some code into a cleaner role setup. So, I ended up with a $package_that_consumes_me object that said it had the role applied but none of the role methods. I'm just whining because I couldn't figure out how to debug any of this :) That was very hard to debug :)
Marking this resolved since there's really nothing (sane) we can do about this in Moose, AFAICT.