Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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 meditating upon the Monastery: (5)
As of 2024-07-16 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.