deepfryed has asked for the wisdom of the Perl Monks concerning the following question:

O wise ones, I tripped on an issue while using lvalue accessors for something I am cooking up. perl debug does *not* like it, so mutators do not work in debug. Is there a workaround for this, or should my lvalue'd subs be going the way of the dodo ?
#!/usr/bin/perl use strict; use warnings; my $foo = 1; sub foo : lvalue { $foo }; foo() = 10; #will print 1 in perl -d print foo(), $/;

Replies are listed 'Best First'.
Re: lvalue and perl debug
by ikegami (Patriarch) on Dec 09, 2007 at 21:12 UTC
    Considering the limited usefulness of lvalue subs in Perl (i.e. you can't validate or otherwise manipulate the value assigned to a function), they just add visual confusion. I don't see any value in them as they currently exist.
      I thought I replied to this one earlier, but it did not show up. Validation can be done using tied hashes or a sep. validate method. My only gripe at this point is not being to use lvalue subs in debug.
        don't you have to "use subs" or other some such pragma?
        the hardest line to type correctly is: stty erase ^H
Re: lvalue and perl debug
by doom (Deacon) on Dec 10, 2007 at 03:24 UTC
    I have a tentative rule-of-thumb that if something breaks the debugger, it should probably be avoided. It's one of the warning signs that you're being too clever.
      lvalue subs are experimental and have been since what 5.006 ? perltodo does say lvalue subs don't work in debugger since DB::sub ignores attributes and would be good to fix (fix debugger i.e.) I am wondering if anyone has found a workaround, I am still in favor of using lvalue subs, as it's syntactically more elegant.
        this is already reported in perl bug #7013
        http://rt.perl.org/rt3/Public/Bug/Display.html?id=7013
        
        I am patching pp_hot.c, perl5db.pl. Stuff like dprof will need fixing too.