Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: [Original edit by JustinMason]

...

  • Let's say you have a perl-style accessor $self->foo(), which is used to access the value $self->{foo}.
  • $self->{foo} is currently eq 'bar'.
  • A caller comes along with a variable $, and wants to set the foo value to whatever's in $. They therefore call $self->foo($_).
  • The bug: if $_ is undef, that means that $self->foo(undef) is called. In a perl-style accessor, that is considered a 'get' operation instead of a 'set', so after that call, $self->{foo} is still set to 'bar'.

In other words, it's impossible to use a perl-style accessor to set a value to 'undef', and it's easy to accidentally perform a no-op instead of a set. This has bitten us in the past.

...