Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Good practice for OO module defaults

by QM (Parson)
on Apr 10, 2019 at 10:13 UTC ( [id://1232397]=note: print w/replies, xml ) Need Help??


in reply to Good practice for OO module defaults

Option 2: Memoise __DATA__

Can you have the package read __DATA__ and fill a package variable, if the package variable isn't defined yet? Something like:

{ my %config; sub new { if (not %config) { %config = read_config_from(__DATA__); } # Now create the object... } }

I'm sure you could make this more flexible, reading from __DATA__ unless passed some other file or file handle.

-QM
--
Quantum Mechanics: The dreams stuff is made of

2019-04-11 Athanasius fixed opening code tags

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2025-06-22 21:11 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.