Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

unimatrix (1124)

unimatrix
  (email not shown publicly)
http://www.codewerk.com

Journal of unimatrix (1124)

Friday May 18, 2001
03:38 PM

Fun with Attributes

[ #183 ]

Got into attributes today. Damian's Attribute::Handlers really makes this easy. The result so far are the following three modules:

Attribute::TieClasses - attribute wrappers for CPAN Tie classes. The following lines load in Tie::Scalar::Timeout and tie()s $k with those options

            use Attribute::TieClasses;
            my $k : Timeout(EXPIRES => '+2s');

Attribute::Memoize - Attribute interface to Memoize.pm

            use Attribute::Memoize;
            sub fib :Memoize {
                            my $n = shift;
                            return $n if $n 2;
                            fib($n-1) + fib($n-2);
            }

Attribute::Abstract - implementing abstract methods with attributes

            package SomeObj;
            use Attribute::Abstract;

            sub new { ... }
            sub write : Abstract;

Now, if properties (in Perl 6 jargon) were modifiable at runtime, it would open the door to aspect-oriented programming. There might be a little talk at YAPC::NA and/or YAPC::Europe on that; so far there is a proof-of-concept implementation of aspects using the flexibility afforded by the debugger. More on that later.