I'm certainly not a guru, and didn't even knew or realized that 'lvalue' exists. So thanks for bringing it up :)
Aside from that, just my opinion: That kind of API is quite weird. I usually write such methods like you did, with an optional $value argument. I guess what I dislike about that lvalue API is, that it looks like action at a distance when skimming through code:
vs.:my $v = $self->header ('test') = "fail"; # :-)
my $v = $self->header ('test', 'fail');
When you skim over the second example you immediately recognize the missing closing ')'. Of course the first example is also an example of bad formatting, so this might not be an actual issue. I'm just not used to assigning to subroutines.
But that aside: Did you think about returning object handles where you overload the '='? In C++ that is done quite often. Then even this would work:
my $hdr_slot = $self->header ('test'); $hdr_slot = "new value"; # Set print "New header: $hdr_slot\n"; # Get
In reply to Re: Mixed lvalue/rvalue sub function
by elmex
in thread Mixed lvalue/rvalue sub function
by mscharrer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |