Detecting assignment event for AUTOLOAD'd lvalue subs ?
renodino
created: 2006-02-02 14:55:50
I'm seeking some insight, and maybe some code snippets, on how to mingle lvalue subs and AUTOLOAD. I've reviewed [id://424644] and peeked at [cpan://Want], and a few other things Super Search turned up, but can't seem to find the right bits.

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

sub proxiedMethod : lvalue {
	my $this = shift;
	$this->{_value};
}
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 ?

Re: Detecting assignment event for AUTOLOAD'd lvalue subs ?
created: 2006-02-05 12:04:28
Sorry, I know this isn't addressing the root of your problem, but have you considered using Class::Std instead of AUTOLOAD? I've been going through 'Perl Best Practices' by Damian Conway, and he says there that 'AUTOLOAD() doesn't promote efficiency, conciseness, robustness, or maintainability, and is best avoided entirely'. In a nutshell, his reasoning is that if there are two or more AUTOLOAD() definitions, the second may be the one you want, but it would never get a chance to handle the method. I think he's implying that it makes it a headache to maintain and could introduce bugs into your code.

Well, I can see value in what he's saying, but I know that every situation is different, e.g. it might be too hard to refactor the code at this point, etc. I get the sense your case may be one of these, but just thought I'd bring it up....

Re^2: Detecting assignment event for AUTOLOAD'd lvalue subs ?
created: 2006-02-05 12:36:02
Let me start by saying I don't buy the inside-out thing, so I'd be disinclined to use Class::Std in the first place. (not a knock on Mssr. Conway, I'm heavy user of his excellent Text::Balanced module)

That being said, Thread::Apartment's use of AUTOLOAD is very focused: its simply a way for client proxies to handle any method an invokant might call, without forcing the proxied object to explicitly install every exported method into the proxy. I had originally considered the latter approach, but soon realized that for some legacy modules (e.g, Perl/Tk), it might be nearly impossible to enumerate all the methods. Note that Thread::Apartment does permit the proxied object to explicitly declare its exported methods to the proxy, but also permits a "wildcard" to permit arbitrary method calls, which can be rejected by the proxied object as needed.

I'd also argue that AUTOLOAD has proven useful to simplify mapping to Web services (see Net::eBay).

However, using AUTOLOAD in an inheritance hierarchy is probably asking for trouble.

perlmonks.org content © perlmonks.org and bowei_99, renodino

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03