Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Using ArrayRef data members in Moose

by friedo (Prior)
on Jul 01, 2008 at 21:55 UTC ( [id://695037]=note: print w/replies, xml ) Need Help??


in reply to Using ArrayRef data members in Moose

This isn't really a Moose issue, it's a Perl one. push and pop must take an array, not an array reference. So you'll need to dereference the arrayref to use those functions on it. You could easily add a method to wrap push and pop, but that seems kinda lame.

There's MooseX::AttributeHelpers::Collection::Array, which certainly sounds like it would be useful, but it beats the hell outta me what it does. Unfortunately I'm quite the Moose n00b myself.

Replies are listed 'Best First'.
Re^2: Using ArrayRef data members in Moose
by dmorgo (Pilgrim) on Jul 01, 2008 at 22:55 UTC
    True.

    By way of contrast, I figured out the sugar for using HashRefs. Hit on this by "genetic programming" -- trying different things until something worked:

    $obj->count_by_word()->{$word} = $count;
    It would be great if there was something similarly simple for arrayref access -- I'm suspecting that there is, and I just haven't found it.
      I think that it works quite the same with arrayrefs:
      $obj->weight()->[0] = 10;
      By way of contrast, I figured out the sugar for using HashRefs.

      This is not sugar at all, this is just how HASH refs work. The "count_by_word" accessor is simply returning the HASH ref value that is stored, nothing more nothing less.

      -stvn
        Ah, yes. Now I get it. Thanks.

        And thanks also to karavelov for the example.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://695037]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found