If you have ever written any Perl OO code, I recommend you to take a look at Luke Palmer's CPAN module Perl6::Attributes, which is extremely simple and handy.
Instead of writing something like
sub method {
my $self = shift;
$self->{attr} = '...';
}
we can now write
sub method {
my $self = shift;
$.attr = '...';
}
in Perl5.
Another example is replacing the ugly syntax
sub method {
my $self = shift;
@{$self->{attrs}} = qw(a b c);
}
with the Perl6-ish syntax
sub method {
my $self = shift;
@.attrs = qw(a b c);
}
You see, it is pretty cool!
I've already had a try in my recent Perl module developements. Perl6::Attributes makes the source of my Perl OO modules amazingly neat.
use Lexical::Attributes;
class MyClass;
has ($.foo, @.bar, %.baz) is rw;
sub new {bless \do {my $v} => shift}
method something {
# Look, no '$self = shift' needed.
$self -> whatever ();
return $.foo + $.bar [1]
}
Is this more Perl6ish than Perl6?
n1vux on 2005-11-29T19:20:48
Is Lexical::Attribute more like Perl6 attributes than Perl6::Attributes is?Re:Is this more Perl6ish than Perl6?
Abigail on 2005-11-29T21:40:23
I don't know. To be perl6ish was only a minor issue for Lexical::Attributes. And in certain ways, it deviates on purpose (private attributes also use a dot as a secondary sigil - I don't share Larry's opinion that it's important to have a visual difference between private and non-private attributes)Re: Lexical::Attributes
agent on 2005-12-01T05:47:06
Thank you for your advice, Abigail.
Yep, Lexical::Attributes seems to be more Perl6-ish and hence even more revolutionary.
But it also deserves more effort to get used to the syntax in Perl5 modules.:=)