Scalar::Defer

Scalar::Defer is a Perl module to calculate values on demand.
Download

Scalar::Defer Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Audrey Tang
  • Publisher web site:
  • http://search.cpan.org/~adamk/Module-Install-0.68/lib/Module/Install/PAR.pm

Scalar::Defer Tags


Scalar::Defer Description

Scalar::Defer is a Perl module to calculate values on demand. Scalar::Defer is a Perl module to calculate values on demand.SYNOPSIS use Scalar::Defer; # exports 'defer' and 'lazy' my ($x, $y); my $dv = defer { ++$x }; # a deferred value (not memoized) my $lv = lazy { ++$y }; # a lazy value (memoized) print "$dv $dv $dv"; # 1 2 3 print "$lv $lv $lv"; # 1 1 1 my $forced = force $dv; # force a normal value out of $dv print "$forced $forced $forced"; # 4 4 4This module exports two functions, defer and lazy, for building values that are evaluated on demand. It also exports a force function to force evaluation of a deferred value.defer {...}Takes a block or a code reference, and returns a deferred value. Each time that value is demanded, the block is evaluated again to yield a fresh result.lazy {...}Like defer, except the value is computed at most once. Subsequent evaluation will simply use the cached result.force $valueForce evaluation of a deferred value to return a normal value. If $value was already normal value, then force simply returns it.NOTESDeferred values are not considered objects (ref on them returns 0), although you can still call methods on them, in which case the invocant is always the forced value.Unlike the tie-based Data::Lazy, this module operates on values, not variables. Therefore, assigning into $dv and $lv above will simply replace the value, instead of triggering a STORE method call.Also, thanks to the overload-based implementation, this module is about 2x faster than Data::Lazy.Requirements:· Perl Requirements: · Perl


Scalar::Defer Related Software