in reply to Re^3: Setting accessor with Object::Tiny
in thread Setting accessor with Object::Tiny
while (($key, $value) = splice @_, 0, 2) { $self->{$key} = $value }
Although I notice that the while-loop version allows assignment of an unpaired key/value (i.e., if the shift-ed @_ array has an odd number of elements, the last element/key of the array has no value and is assigned as undef) without a warning. The list assignment version must be changed to something like
%$self = (%$self, @_, @_ & 1 ? undef : ());
to avoid a warning (if this is desireable), and this, I must admit, is a bit more messy.
Update: But I guess a simple
no warnings 'misc';
%$self = (%$self, @_);
would suppress that warning just as well.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Setting accessor with Object::Tiny (updated)
by jcb (Parson) on Aug 12, 2019 at 06:23 UTC |