in reply to How to create multipurpose lvalue sub such as CGI::param ?
The perlsub section on Lvalue subs warns, "Lvalue subroutines are still experimental and the implementation may change in future versions of Perl." That said, this seems to do what you want:
package MyTest; sub new { bless { 'session' => {} }, shift; } sub param : lvalue { my $self = shift; my $name = shift; if ( ! defined $name && wantarray ) { my @out = keys %{$self->{session}}; return @out; } $self->{session}->{$name}; } 1;
|
|---|