|No such thing as a small change|
Re: $foo->bar = 14;by BrowserUk (Pope)
|on Dec 29, 2002 at 23:32 UTC||Need Help??|
I had similar ideas regarding lvalue subs for accessor/mutator methods (see: (my?) problem with re-blessed references(?)), and I still find the idea appealing. The limitations of the current experimental implementation of lvalue subs render them such that for anything other than trivial cases, the limitations outway the benefits currently.
As I described in What the [sub]in 'L value do they have?, I thought I saw ways to improve the current implementation, but it may be that doing so would limit or corrupt their existing utility.
I haven't yet managed to wrap my head around how the sub could be given access to the assigned value in
$foo->bar =~ s/a/b/g;
prior to assignment, without destroying the efficiency and utility of that construct.
One thought that does come to mind is that lvalue accessor/mutator methods could be used internally to a class for accessing their own instance data in true OO-style, but that the published interface would not expose those methods. This would retain the benefits of minimising changes within the class if the structure of the instance data changed, but would also remove some of the overhead in having non-mutator methods access instance data via them.
I just re-read that and whilst it says what I am trying to say, it's about as clear as mud and I don't see how to easily improve it. Perhaps a simple example.
Examine what is said, not who speaks.