develooper Front page | perl.perl5.porters | Postings from March 2006

Re: how should %^H work with lexical pramas

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
March 30, 2006 09:42
Subject:
Re: how should %^H work with lexical pramas
Message ID:
20060330174211.GJ32132@plum.flirble.org
On Wed, Mar 29, 2006 at 03:15:17PM +0200, Rafael Garcia-Suarez wrote:
> Nicholas Clark wrote:
> > And given that you might want to implement your pragma with more than one
> > level of subroutine, I infer that you might need to get at $^{foo} from
> > somewhere up your caller's scope. This starts to sound like the correct
> > hash should be returned as another value from caller.
> 
> Just like the warnings bitfield, yes.

So, basically, if this test passes, user defined lexical pragmas are go:

use warnings;
use strict;
use Test::More tests=>5;

sub get_dooot {
    my @results = caller(0);
    $results[10]->{dooot};
}

{
    is(get_dooot(), undef);
    BEGIN {
        $^H{dooot} = 1;
    }
        is(get_dooot(), 1);

    BEGIN {
        $^H{dooot} = 42;
    }
    {
        {
            BEGIN {
                $^H{dooot} = 6 * 9;
            }
            is(get_dooot(), 54);
        }
        is(get_dooot(), 6 * 7);
    }
    is(get_dooot(), 6 * 7);
}

__END__

?


(in that at runtime you can read the value that %^H had in that scope, with
%^H propagating correctly into blocks, and behaving correctly when redefined
within a block)

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