Re: How to make this nicer

2009-06-04 Thread Yuri Shtil

Hans Dieter Pearcey wrote:

On Sun, May 03, 2009 at 11:00:30AM -0700, Yuri Shtil wrote:
  

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.



use MooseX::Role::Parameterized

hdp.
  

This works perfectly, thank you. I have one more question.

How do I access the container object (where the with is) from the role 
method?


--

Yuri



Re: How to make this nicer

2009-06-04 Thread Yuri Shtil


Chris Prather wrote:

On Thu, Jun 4, 2009 at 10:34 PM, Yuri Shtilyu...@juniper.net wrote:

  

How do I access the container object (where the with is) from the role
method?



$self ?

-Chris
  


The first thing on the arg list to self is the parameter, no self here.
The named parameter consumer points to Moose::Meta::Class.
How do I extract the real class from it?

--

Yuri



How to make this nicer

2009-05-03 Thread Yuri Shtil

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



Re: How to make this nicer

2009-05-03 Thread Hans Dieter Pearcey
On Sun, May 03, 2009 at 11:00:30AM -0700, Yuri Shtil wrote:
 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.

use MooseX::Role::Parameterized

hdp.