in reply to Re^7: can sub check context for lvalue vs rvalue context?
in thread can sub check context for lvalue vs rvalue context?
If something is being assigned to 'path', then I'd know I need the lvalue -- and return something likep->{_path}
So if someone want to read path, they would get a simple, direct reference (no tied var overhead), but if they wrote to it, it needs to store the new value, and clear the internal value for _url so it can be re-composed.$p->{tied_path} sub callback_for_STORE_into_tied_path { my $p=shift; my $newvalue; $p->{_path}=$newvalue; $p->{_url}=undef; ... $p->{_path}; } ...later...in sub url(;$) { my $p=shift; $p->compose_url_from_parts() unless defined $p->{_url}; $p->{_url} }
At no point should I need to return a constant -- just a choice between the actual var in the hash, or a tied var.
If I knew the lvalue-context, is there a reason why that wouldn't work?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: can sub check context for lvalue vs rvalue context?
by BrowserUk (Patriarch) on May 10, 2018 at 22:51 UTC | |
by perl-diddler (Chaplain) on May 11, 2018 at 16:19 UTC | |
by BrowserUk (Patriarch) on May 12, 2018 at 07:44 UTC | |
by perl-diddler (Chaplain) on May 14, 2018 at 03:59 UTC | |
by BrowserUk (Patriarch) on May 14, 2018 at 14:16 UTC | |
by LanX (Saint) on May 11, 2018 at 17:02 UTC | |
by perl-diddler (Chaplain) on May 14, 2018 at 03:53 UTC |