renodino has asked for the wisdom of the Perl Monks concerning the following question:
I'm using AUTOLOAD to provide a client proxy wrapper for apartment threaded objects. All works well for the usual behaviors, and I think I've worked out how to handle proxied closures. I'd also like to be able to handle proxied lvalue subs as well, but can't quite figure out how to trap the actual assignment event so it can be propagated back to the proxied object. I don't want to use tied objects, since the client proxy objects are usually threads::shared (to make it easy to pass them between threads).
So, assuming the proxied object has
and assuming the proxied object knows how to tell its proxy that proxiedMethod() is lvalue, and the proxy's AUTOLOAD() uses WANT('LVALUE') to test if the method is being used as lvalue, how can the proxy be notified of any eventual assignment, so that it can pass the value back to the proxied object ?sub proxiedMethod : lvalue { my $this = shift; $this->{_value}; }
Update:
Given the deafening silence, it appears I've either
However, upon further reflection, this issue is a bit thornier than I realized...
However, since the client proxy can be shared by multiple threads, and hence the lvalue could be concurrently updated/read by multiple threads, there needs to be some locking added...
All in all, it may be a bad idea...or at least an idea whose time has not yet come. Perhaps Perl6 or Ponie will address this by relaxing the "can't tie a threads::shared" requirement.
FWIW: My original purpose was to create a variant of DBIx::Threaded that replaces the non-shared, tied client proxies with threads::shared, untied versions, in order to simplify and speed up the passing of proxy dbh's/sth's between threads. The current version has to do a lot of marshalling/unmarshalling when the proxies are passed around. If the proxies were made threads::shared, passing them around would be faster/simpler.
So if "DBIx::Threaded::Untied" replaced DBI's tied members (e.g., AutoCommit, PrintWarn, RaiseError, etc.) with lvalue subs of the same name, the impact on code would be a bit less painful, e.g.,
becomes$dbh->{AutoCommit} = 1;
$dbh->AutoCommit = 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Detecting assignment event for AUTOLOAD'd lvalue subs ?
by bowei_99 (Friar) on Feb 05, 2006 at 17:04 UTC | |
by renodino (Curate) on Feb 05, 2006 at 17:36 UTC |