in reply to Good practice for OO module defaults

Hello davies,

I'm not a OO expert (in what I'm expert? ;) but I almost always start with something like (perl 5.14 5.10 (see below GrandFather's answer) required to use //= ):

sub new{ my $class = shift; my %conf = validate_conf( @_ ); return bless { %conf }, $class; } sub validate_conf{ my %conf = @_; $conf{ map_colors } //= 16; $conf{ map_area_w } //= 50; $conf{ map_area_h } //= 20; # more logic if needed.. return %conf; }

So the fourth option for me

HtH

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Good practice for OO module defaults
by GrandFather (Saint) on Apr 08, 2019 at 09:57 UTC

    Actually defined or // has been around since 5.10.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond