Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: delegate Moose accessors to a HASH?

by perl5ever (Pilgrim)
on Jun 23, 2011 at 19:42 UTC ( [id://911142]=note: print w/replies, xml ) Need Help??


in reply to Re: delegate Moose accessors to a HASH?
in thread delegate Moose accessors to a HASH?

The setter doesn't seem to work:
$foo->that(10) # sets $foo->data->{that} = 10

I can make this work:

$foo->that = 10
by adding :lvalue to the sub declarations, but that's not what I want.

Replies are listed 'Best First'.
Re^3: delegate Moose accessors to a HASH?
by ikegami (Patriarch) on Jun 23, 2011 at 19:59 UTC

    Sorry, I wrote it as a getter, not an accessor.

    handles => { this => sub { @_ == 1 ? $_[0]->data->{this} : $_[0]->data->{this} = $_[1] }, that => sub { @_ == 1 ? $_[0]->data->{that} : $_[0]->data->{that} = $_[1] }, },

    You can use a map to avoid duplication and/or an accessor generating function.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-23 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found