Thanks to Damian's Attribute::Handlers it's now possible to do what I
wanted to do for some time (but haven't quite gotten around to) and very
easily (and it's on its way to CPAN; suggestions/patches welcome):


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;



package Attribute::Memoize;

use warnings;
use strict;
use Attribute::Handlers;
use Memoize;

our $VERSION = '0.01';

sub UNIVERSAL::Memoize :ATTR(CODE) {
         my ($package, $symbol, $options) = @_[0,1,4];
         $options = [ $options ] unless ref $options eq 'ARRAY';
         memoize $package . '::' . *{$symbol}{NAME}, @$options;
}

1;


Marcel

--
$ perl -we time
Useless use of time in void context at -e line 1.

Reply via email to