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: <%-{-{-{-<
In reply to Re^4: Setting accessor with Object::Tiny (updated)
by AnomalousMonk
in thread Setting accessor with Object::Tiny
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |