The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Tie::LazyFunction - sugar to defer evaluation in a tied scalar

SYNOPSIS

   use Tie::LazyFunction;
   tie my $lazyvar, Tie::LazyFunction => 
      sub {
        something we want to defer
      }, 
      $arg1var, $arg2var, ... $ #variables which will hold arguments to the sub
   ; 

DESCRIPTION

This short module facilitates binding a coderef to a scalar in such a way that the coderef will be evaluated when the value of the scalar is taken.

When six or fewer arguments are specified after the coderef at tie time, the arguments are not evaluated until they are evaluated within the code. With seven or more arguments, arguments are evaluated at function call time and passed by value.

All arguments are referred to by reference only until FETCH time.

EXPORT

nothing

HISTORY

0.01

written in response to discusison of simple lazy variables on perl-5 porters mailing list

FUTURE

It is frustrating that there is no complementary operation to @Refs = \( @Scalars ) aside from @Derefs = map { $$_ } @Refs which fetches the references instead of simply dereferencing them.

AUTHOR

Copyright (C) 2005 david nicol davidnico@cpan.org released under your choice of the GNU Public or Artistic licenses

SEE ALSO

Data::Lazy provides much more than this does

Tie::Function makes function calls look like hash lookups