in reply to Are lvalue methods (as properties) a good idea?
They're at their best when used with lexical closures. They make a very nice way to get subroutine-style scoping for class variables. That means they replace package globals with a slightly different scoping model. They have the advantage of being overridable and inheritable.
Lexical closures on lvalue subs are less handy for object methods. You need to define the sub in the constructor and keep a reference to it around. It looks like that is what the package you mention probably does. Used as an lvalue, a naive instance method finds it tricky to associate itself with the correct object, and if the instance method didn't see the object data's my call when defined, trouble can result.
I think that lvalue subs are stable to use for scalars. Afaik there are problems with list context for arrays and hashes. A fix for those is likely to break something.
Lvalue subs are tremendous fun to experiment on. Here's an example whose effects are enlightening to investigate,
my @crefs = do { my $foo = \$_; ( sub :lvalue { $$foo }, sub :lvalue { $foo } ) };
After Compline,
Zaxo
|
---|