I am trying to implement the Moose :: Role class, which behaves like an abstract class in Java. I would like to implement some methods in Role, but then be able to redefine these methods in specific classes. If I try this using the same style that works when I extend classes, I get a Cannot add an override method if a local method is already present error. Here is an example:
My abstract class:
package AbstractClass; use Moose::Role; sub my_ac_sub { my $self = shift; print "In AbstractClass!\n"; return; } 1;
My specific class:
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;
And then:
use Class; my $class = Class->new; $class->my_ac_sub;
Am I doing something wrong? Is what I'm trying to do differently? Am I not trying to do this at all?
source share