Skip Menu |
 

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 82711
Status: resolved
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: ovid [...] cpan.org
Cc: dagolden [...] cpan.org
LEONT [...] cpan.org
AdminCc:

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



Subject: Requirements in roles should not be checked until all roles are consumed
Download (untitled) / with headers
text/plain 1.1k
I was doing some refactoring in some code when I couldn't figure out why Moo was saying I was missing some requirements, despite a consumed role clearly providing said requirements. I can replicate the bug in Moo 1.000007 with the following sample code: { package Role1; use Moo::Role; sub i_am_required { return 'this is required' } } { package Role2; use Moo::Role; requires 'i_am_required'; sub another_method { 'this is provided' } } { package Consumer; use Moo; with qw(Role2 Role1); } When you run this you get: Can't apply Role2 to Consumer - missing i_am_required at ... However, in the Consumer class, if you reverse Role2 and Role1 in the with() statement, the code runs just fine. Suggested fix (sans code): delay checking whether or not a class provides all methods required until all roles are consumed and provided methods are flattened into the class. Cheers, Ovid
Download (untitled) / with headers
text/plain 1.2k
On Tue Jan 15 06:21:09 2013, OVID wrote: Show quoted text
> I was doing some refactoring in some code when I couldn't figure out > why > Moo was saying I was missing some requirements, despite a consumed > role > clearly providing said requirements. > > I can replicate the bug in Moo 1.000007 with the following sample > code: > > { > package Role1; > use Moo::Role; > sub i_am_required { return 'this is required' } > } > { > package Role2; > use Moo::Role; > requires 'i_am_required'; > sub another_method { 'this is provided' } > } > { > package Consumer; > use Moo; > with qw(Role2 Role1); > } > > When you run this you get: > > Can't apply Role2 to Consumer - missing i_am_required at ...
I've hit the same bug before. The compose-mutualists branch of Role::Tiny contains some failing tests. Show quoted text
> However, in the Consumer class, if you reverse Role2 and Role1 in the > with() statement, the code runs just fine. > > Suggested fix (sans code): delay checking whether or not a class > provides all methods required until all roles are consumed and > provided > methods are flattened into the class.
That would fix requires, but not method modifiers. Fixing that seems to be more complicated. Leon
Download (untitled) / with headers
text/plain 1.5k
On Mon Jan 28 07:13:34 2013, LEONT wrote: Show quoted text
> On Tue Jan 15 06:21:09 2013, OVID wrote:
<snip> Show quoted text
> > Suggested fix (sans code): delay checking whether or not a class > > provides all methods required until all roles are consumed and > > provided > > methods are flattened into the class.
> > That would fix requires, but not method modifiers. Fixing that seems
to Show quoted text
> be more complicated.
Interestingly, I just tracked down a bug where one role had method modifiers and another role had the methods. I kept getting the following error: The method 'get_publisher' is not found ... I couldn't figure it out because the method existed (there was an extra "around" in the consuming class which was a red herring), but then I remembered that this was Moo, and not Moose, and checked this ticket. Sure enough, I once again think that flattening the methods into the class would make this bug go away. The following code replicates the error (reverse the roles in the with() statement to make this bug go away). { package Role1; use Moo::Role; around get_publisher => sub { my ( $orig, $self ) = @_; warn "in around"; $orig->($self); }; } { package Role2; use Moo::Role; sub get_publisher { warn "In sub"; } } { package Consumer; use Moo; with qw(Role1 Role2); } Consumer->new->get_publisher; Cheers, Ovid
Fixed in 1.003000


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.