Hash::Util's lock_keys

William Blunn bill+london.pm at blunn.org
Wed Feb 19 17:46:45 GMT 2014


On 19/02/2014 13:26, Smylers wrote:
> The problem was that if it's invoked with:
>
>    $obj->some_method(\%opt);
>
> then setting defaults inside the method actually changes the caller's
> %opt. ...
>
> Whereas with:
>
>    sub some_method {
>      my ($self, %args) = @_;
> ...
>
> that possibility doesn't occur. And having fewer %$-s and {...}-s from
> de- and re-referencing makes the code a little less distracting as your
> mind tracks what's going on.

+1

Several's the time I’ve reviewed code with the sentiment “This code 
undocumentedly and PoLA-violatingly modifies the caller’s data”.

Regads,

Bill


More information about the london.pm mailing list