Package Info

perl-constant-defer


Constant Subs with Deferred Value Calculation


Development/Libraries/Perl

'constant::defer' creates a subroutine which on the first call runs given code to calculate its value, and on any subsequent calls just returns that value, like a constant. The value code is discarded once run, allowing it to be garbage collected.

Deferring a calculation is good if it might take a lot of work or produce a big result but is only needed sometimes or only well into a program run. If it's never needed then the value code never runs.

A deferred constant is generally not inlined or folded (see the perlop/Constant Folding manpage) since it's not a single scalar value. In the current implementation a deferred constant becomes a plain constant after the first use, so may inline etc in code compiled after that (see the /IMPLEMENTATION manpage below).

See examples/simple.pl in the constant-defer source code for a complete sample program.


License: GPL-3.0+
URL: http://search.cpan.org/dist/constant-defer/

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
6-bp155.2.10 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp154.1.22 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp153.1.14 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp152.3.15 info GA Release 2020-04-16 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp151.2.14 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer
6-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-constant-defer