Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Passing arrayref to Moose attributes

by tobyink (Abbot)
on Apr 20, 2013 at 17:46 UTC ( #1029670=note: print w/replies, xml ) Need Help??

in reply to Re: Passing arrayref to Moose attributes
in thread Passing arrayref to Moo attributes

Actually, that code won't work especially well either. (Try calling $maze->my_array.) This is because Moo lacks Moose's native attribute traits feature. (MooX::HandlesVia might help though.)

Also, FYI, Type::Tiny should run measurably faster than MooX::Types::MooseLike::Base, especially for a compound type constraint like ArrayRef[ArrayRef[Str]]. See my benchmarks.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^3: Passing arrayref to Moose attributes
by davido (Archbishop) on Apr 21, 2013 at 04:11 UTC

    I don't think that's a Moo/Moose-compatibility issue (I could be wrong, and if so, would like additional clarification). It would be equally problematic with Moose, wouldn't it? At least after converting it to Moose by quoting the isa component, I get:

    Cannot delegate my_array to elements because the value of maze_map is +not an object (got 'ARRAY(0x163b880)') at...

    ...which seems to be the same type of error produced under Moo, with a slightly different message.

    But I suppose I should be asking for clarification. Should that work under Moose?


      Under Moose you need to add traits => ["Array"] to the attribute declaration. See Moose::Meta::Attribute::Native::Trait::Array.

      With Moo you'd use handles_via => "Array" but you'd need to install MooX::HandlesVia first.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

        Thanks! :)


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029670]
and the voices are still...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2016-12-10 15:41 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (163 votes). Check out past polls.