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
|
|---|