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

Re: A user pragma example

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
April 1, 2006 07:18
Subject:
Re: A user pragma example
Message ID:
20060401151822.GP32132@plum.flirble.org
On Fri, Mar 31, 2006 at 04:32:38PM -0600, David Nicol wrote:
> so something like this would work?
> 
> package namedscope;
> =pod
> 
> Scalars can be tied to this package and they will be in a
> virtual scope named at compile time using the namedscope pragma.
> 
> Example:
> 
>      tie our $n, 'namedscope';
> 
>      {
>          use namedscope 'foo';
>          $n = "in foo scope";
>      }
>      {
>          use namedscope 'bar';
>          $n = "in bar scope";
>      }
> 
>      {
>          use namedscope 'foo';
>          print "$n\n";
>          use namedscope 'bar';
>          print "$n\n";
>      };
> 
> =cut
> 
> sub import{
>    $^H{namedscope} = shift;
> };
> sub TIESCALAR{
>    return bless {};
> };
> sub STORE{
>    $_[0]->{$^H{namedscope}} = $_[1]
> };
> sub FETCH{
>    $_[0]->{$^H{namedscope}}
> };

No. It's going to need the games with caller, rather than accessing %^H,
simply because the information it needs to get is stored in the very structure
that caller already reads.

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