in reply to Use method/function signatures with Perl
I think the entire idea of rvalue accessor methods is flawed, now that we have the possibility to create lvalue ones. Since years ago, I have made programming much easier for myself by inventing some very simple rules:
Value validation used to be a good reason not to use lvalues. But there is Attribute::Property now. Not that I use it myself, though: sub foo : lvalue { shift->{foo} } (or sub foo : lvalue { $foo{+shift} } for inside-out objects) has proven to work very well, and value validation is something I don't do much (I expect people to RTFM).
$person->name; # get the name $person->name("Ovid"); # set the name $person->name(do { (my $temp = $person->name) =~ s/Ovid/Juerd/; $temp +}); $person->name($person->name . "\n"); $person->name(do { chomp(my $temp = $person->name); $temp });
$person->name; $person->name = "Ovid"; $person->name =~ s/Ovid/Juerd/; $person->name .= "\n"; chomp $person->name;
This still throws values in @_ away. But as idiomatically this syntax is used without any parentheses at all, that is not a problem.
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use method/function signatures with Perl
by tilly (Archbishop) on Dec 06, 2004 at 22:47 UTC | |
by Juerd (Abbot) on Dec 07, 2004 at 15:49 UTC | |
by tilly (Archbishop) on Dec 07, 2004 at 16:49 UTC | |
by Juerd (Abbot) on Dec 07, 2004 at 18:53 UTC |