Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

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

People
Owner: Nobody in particular
Requestors: JCROSSWH [...] cpan.org
Cc:
AdminCc:

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



Subject: Unable to override Moose::Role method in Moose subclass
I am trying to override in a Moose class that is originally defined in a Moose::Role. The Moose class is a direct implementer of the Role. When trying to do this, I get the error 'Cannot add an override method if a local method is already present' even though the method is not defined in the Moose class. Here is an example that will generate the error: package AbstractClass; use Moose::Role; sub my_ac_sub { my $self = shift; print "In AbstractClass!\n"; return; } 1; package Class; use Moose; with 'AbstractClass'; override 'my_ac_sub' => sub { my $self = shift; super; print "In Class!\n"; return; }; __PACKAGE__->meta->make_immutable; 1; use Class; my $class = Class->new; $class->my_ac_sub; I expect to see: In AbstractClass! In Class! - but instead I get the error mentioned above. Please let me know if you need more detail.
Subject: Re: [rt.cpan.org #89289] Unable to override Moose::Role method in Moose subclass
Date: Mon, 07 Oct 2013 09:08:44 -0700 (PDT)
To: "bug-Moose [...] rt.cpan.org" <bug-moose [...] rt.cpan.org>
From: "Chris Prather" <perigrin [...] prather.org>
This is working as expected. The 'override' keyword is used only to override a method aquired through Inheritance. Methods aquired through Role composition are *by definition* not inherited.  To do what you want you'd need to do the following instead: around 'my_ac_sub' => sub {  my $next = shift; my $self = shift;  $self->$next(); print "In Class!\n";  return;  };  On Mon, Oct 7, 2013 at 1:44 AM, Joel Crosswhite via RT <bug-moose@rt.cpan.org="mailto:bug-moose@rt.cpan.org">> wrote: Mon Oct 07 01:44:21 2013: Request 89289 was acted upon. Transaction: Ticket created by JCROSSWH Queue: Moose Subject: Unable to override Moose::Role method in Moose subclass Broken in: 2.1005 Severity: Wishlist Owner: Nobody Requestors: JCROSSWH@cpan.org Status: new Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=89289 > I am trying to override in a Moose class that is originally defined in a Moose::Role. The Moose class is a direct implementer of the Role. When trying to do this, I get the error 'Cannot add an override method if a local method is already present' even though the method is not defined in the Moose class. Here is an example that will generate the error: package AbstractClass; use Moose::Role; sub my_ac_sub { my $self = shift; print "In AbstractClass!\n"; return; } 1; package Class; use Moose; with 'AbstractClass'; override 'my_ac_sub' => sub { my $self = shift; super; print "In Class!\n"; return; }; __PACKAGE__->meta->make_immutable; 1; use Class; my $class = Class->new; $class->my_ac_sub; I expect to see: In AbstractClass! In Class! - but instead I get the error mentioned above. Please let me know if you need more detail.
Ok, thank you very much. I wasn't sure if I was using it incorrectly or if it was something that was an oversight. That method works, you can close this ticket.