Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Modules: computing a constant, "on load" or in new()?

by AnomalousMonk (Canon)
on Aug 20, 2013 at 22:28 UTC ( #1050259=note: print w/ replies, xml ) Need Help??


in reply to Modules: computing a constant, "on load" or in new()?

What BrowserUk said.
I would look at it slightly differently. If we are talking about a 'class' constant, i.e., something that is invariant over all class and object methods and all 'free' functions of the class, make it a constant as soon as possible, computed or otherwise. If it's an 'object' constant, i.e., something invariant only over the lifetime of a given object, then, of course, it must be somehow created or defined in the constructor: how else? As an example of the first possibility:

package Foo::Bar; ... use constant RX => qr{ hello }xms; ... sub new { ... } ... sub method { my $self = shift; ... if ($self->{bar} =~ RX) { ... } ... } ... 1;


Comment on Re: Modules: computing a constant, "on load" or in new()?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2016-02-09 21:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (326 votes), past polls