Michael,

Having done this a couple of times with CPAN modules, I agree with Stevan,
delegation is often the quickest way.

However, it is not impossible to use an ArrayRef for it's instance type.  In
fact, Moose makes it quite easy.  Take a look at ODG::Record, a Moose based
record iterator that uses a combination of a HashRef and ArrayRef for its
instance.  Data is stored in the ArrayRef.  Metadata is stored in the
HashRef.  If this kinda thing is useful, it wouldn't be hard to spin a
module that provides this functionality generically.  The only requirement
is that you have to specify which position in the ArrayRef belongs to which
attribute.

 Best,

Chris




On Sun, Feb 22, 2009 at 1:06 PM, Stevan Little <
stevan.lit...@iinteractive.com> wrote:

> Michael,
>
> POE::Wheel::Run::new is being called here, your Moose constructor will
> never be called. Additionally POE::Wheel::Run uses Array refs for it's
> instance type, which would not be compatible with the Hash ref instance type
> that Moose would want to use.
>
> I suggest you first take a look at MooseX::POE to see if that might be able
> to do what you want. If it does not do what you are looking for (or provide
> something similar enough) then I would suggest using delegation here instead
> of inheritance (see the 'handles' option detailed in Moose.pm,
> Moose::Manual::Delegation, and Moose::Cookbook::Basics::Recipe11 for
> constructor args munging). If you don't want to use delegation then I would
> suggest not using Moose in this case.
>
> - Stevan
>
>
> On Feb 22, 2009, at 3:57 PM, Michael Potter wrote:
>
>  Something like:
>>
>> package Proxy;
>> use Moose;
>>
>> extends 'POE::Wheel::Run';
>>
>> has 'type' => (is => 'ro', required => 1);
>>
>> 1;
>>
>> my $proxy = Proxy->new(<normal wheel attrs>,type=>'foo');
>>
>> --------------------
>>
>> Everything works as expected, except for the fact that POE::Wheel::Run
>> complains when it sees the 'type' attr.
>>
>>
>> On Mon, Feb 23, 2009 at 2:58 AM, Stevan Little
>> <stevan.lit...@iinteractive.com> wrote:
>>
>>> Michael,
>>>
>>> Well, if you are extending a non-Moose class, I assume you are calling
>>> the
>>> non-Moose constructor. In which case Moose has nothing to do with this.
>>>
>>> If you are extending a non-Moose class and using the Moose constructor
>>> then,.. well I would need to see some code as there are many different
>>> ways
>>> you could be doing that and so many different ways to solve this problem.
>>>
>>> - Stevan
>>>
>>>
>>> On Feb 22, 2009, at 7:00 AM, Michael Potter wrote:
>>>
>>>  Hi
>>>>
>>>> I am extending a non-Moose class, and I want to add an attribute to my
>>>> derived class. Problem is, the base class complains (loudly) if it
>>>> gets attributes it was not expecting - and it seems the new attribute
>>>> in the derived class get passed down to the base, hence the problem.
>>>> Is there an easy way to remove an attribute from the constructor hash
>>>> once it has been used to initialize an attribute? Something like this
>>>> would be nice:
>>>>
>>>> has type => (
>>>>  is        => 'ro',
>>>>  gobble => 1 # remove element from constructor hash when used to
>>>> initialize this attribute
>>>> );
>>>>
>>>> Cheers
>>>>
>>>
>>>
>>>
>

Reply via email to