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

Re: More concise way to write these accessors?

by BrowserUk (Patriarch)
on Jun 25, 2016 at 04:10 UTC ( [id://1166543]=note: print w/replies, xml ) Need Help??


in reply to More concise way to write these accessors?

Those are weird rw accessors. If the object already has an internal value for this field, ignore any value the user is attempting to set and return the existing value?

But:

sub ip { $_[0]->{ip} //= $_[1] // $_[0]->{conf}{ip} // '0.0.0.0' +} sub port{ $_[0]->{port} //= $_[1] // $_[0]->{conf}{port} // '7800' +}

Or:

eval <<EOA for [ 'ip', '0.0.0.0' ], [ 'port', '7800' ]; sub $_->[0] { \$_[0]->{$_->[0]} //= \$_[1] // \$_[0]->{conf}{$_->[0]} +// \"$_->[1]\" } EOA

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

Log In?
Username:
Password:

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

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

    No recent polls found