develooper Front page | perl.perl5.porters | Postings from May 2010

Re: [perl #6813] tie() magic upsets stack (can't last() outside of block)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
May 4, 2010 02:29
Subject:
Re: [perl #6813] tie() magic upsets stack (can't last() outside of block)
Message ID:
20100504092854.GE2576@plum.flirble.org
On Mon, May 03, 2010 at 05:27:56PM +0100, Dave Mitchell wrote:
> On Thu, Apr 29, 2010 at 10:51:26AM -0700, Eric Brine via RT wrote:
> > A simpler demonstration:
> > 
> > ---- BEGIN CODE ----
> > #!/usr/bin/env perl
> > 
> > use strict;
> > use warnings;
> > 
> > {
> >    package Tie;
> >    sub TIESCALAR { return bless({}, shift); }
> >    sub STORE { next; }
> > }
> > 
> > tie my $x, Tie::;
> > { tied($x)->STORE(123); }  # warns, but works
> > { $x = 123;             }  # warns and dies
> > ---- END CODE ----
> 
> I think this behaviour is correct. Tied method calls shouldn't consider
> any context outside the method call itself. After all, the tied action
> could have been invoked from almost anywhere, including somewhere deep
> within XS code.
> 
> I also think the behaviour is deliberate. Magic method calls are run on a
> new set of stacks, and while die etc will pop back across multiple
> context stacks, pp_next etc only look at the current stack.

Yes, your explanation makes sense. I can't really see that this can be "fixed".

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About