http://qs321.pair.com?node_id=770473


in reply to Re: "Fields" for "Objects"
in thread "Fields" for "Objects"

It's interesting, this is how I write them too. But I noticed lodin's node, which contains an important but subtle difference; by doing this:
sub field { my $self = shift; $self->{field} = $_[0] if @_; ... }
instead of this:
sub field { my ($self,$val) = @_; $self->{field} = $val if defined $val; ... }
you don't run into issues where $self->field(undef) would silently return the old value without changing it, which isn't what you might expect. But because I've seen the second form elsewhere and it's technically better practice to assign @_ to variables I just stuck with it, but clearly the first way is better.