Attribute::Memoize - A Memoize attribute
use Attribute::Memoize; sub fib :Memoize { my $n = shift; return $n if $n < 2; fib($n-1) + fib($n-2); } $|++; print fib($_),"\n" for 1..50;
This attribute makes it slightly easier (and modern) to memoize a function by providing an attribute, :Memoize that makes it unnecessary for you to explicitly call Memoize::memoize(). Options can be passed via the attribute per usual (see the Attribute::Handlers manpage for details, and the Memoize manpage for information on memoizing options):
:Memoize
Memoize::memoize()
Attribute::Handlers
Memoize
sub f :Memoize(NORMALIZER => 'main::normalize_f') { ... }
However, since the call to memoize() is now done in a different package, it is necessary to include the package name in any function names passed as options to the attribute, as shown above.
memoize()
None known so far. If you find any bugs or oddities, please do inform the author.
Marcel Grunauer, <marcel@codewerk.com>
Dan Kogai, <dankogai+cpan at gmail.com>
<dankogai+cpan at gmail.com>
Copyright 2001 Marcel Grunauer. All rights reserved.
Copyright 2006 Dan Kogai. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl(1), Attribute::Handlers, Memoize
To install Attribute::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Attribute::Util
CPAN shell
perl -MCPAN -e shell install Attribute::Util
For more information on module installation, please visit the detailed CPAN module installation guide.