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;
In reply to Re: Modules: computing a constant, "on load" or in new()?
by AnomalousMonk
in thread Modules: computing a constant, "on load" or in new()?
by isync
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |