in reply to Good practice for OO module defaults
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*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Good practice for OO module defaults
by GrandFather (Saint) on Apr 08, 2019 at 09:57 UTC |