Hi All,

Here is a piece of code I have:
-----
package X::Project;
use Moose;
extends 'X';
use MooseX::AttributeHelpers;
use Moose::Util::TypeConstraints;
use namespace::clean;

use MooseX::Method qw/:compiled/;

method procedures => sub {
CODE
};

subtype 'Procedure' => as Any => where {
 my $type = ref($_);
 $type eq 'HASH' || $type eq 'X::Procedure';
};

has '_procedures' => (
 metaclass => 'Collection::Hash',
 is        => 'rw',
 isa       => "HashRef[Procedure]",
 default   => sub { {} },
 provides  => {
   set  => 'set_procedure',
   keys => 'keys_procedure',
 },
 curries => {
   get => {
     get_procedure => sub {
       my $self = shift;
       $self->_get_child( 'procedure', @_ );
       }
   }
 }
);

-----

I have a bunch of subclasses of X like this all having similar code.
For example in the class X::Procedure I would have the same code with procedure replaced by step.

I find it annoying to have to type the same piece of code in each class file. I tried to call a procedure in the base class that would take care of it, but discovered that the method will be created in the base class, not in subclass, I am not sure about properties.

Is there a way to do this in Moose?

--

Yuri

Reply via email to