Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Good practice for OO module defaults

by Discipulus (Canon)
on Apr 08, 2019 at 09:50 UTC ( [id://1232284]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1232284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2025-06-22 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.