You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Barrie Slaymaker <ba...@slaysys.com> on 2001/10/22 16:27:15 UTC

Re: cvs commit: modperl-2.0/ModPerl-Registry TODO

On Mon, Oct 22, 2001 at 08:33:49AM -0000, stas@apache.org wrote:
>    
>   +- the closure issue:
>   +  there was a suggestion from raptor to use goto() to leave the code
>   +  unwrapped in the sub handler, which will solve the closure problem,
>   +  but the problem is that once you leave a subroutine with goto() you
>   +  cannot return, because you aren't in the sub anymore.

The issue I saw with this was that the top-level code outside the subs
in a module is unreachable (I suspect it's freed, but have no clue)
after the module exits.  So, in something like

   package Foo ;

   enter:
       print "entered\n" ;

   sub handler { goto enter }

   1 ;

, by the time you can call handler(), the label "enter" is no longer
reachable.  I suspect it's because the top-level opcodes in a module are
all freed after it is eval()ed.

- Barrie

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: cvs commit: modperl-2.0/ModPerl-Registry TODO

Posted by Stas Bekman <st...@stason.org>.
Barrie Slaymaker wrote:

> On Mon, Oct 22, 2001 at 10:46:04PM +0800, Stas Bekman wrote:
> 
>>It works for me:
>>
>>my $package = << 'END';
>>package Foo ;
>>
>>    enter:
>>        print "entered\n" ;
>>
>>    sub handler { goto enter }
>>
>>    1 ;
>>END
>>
>>eval $package;
>>Foo::handler;
>>
>>prints:
>>
>>entered
>>
> 
> It should print "entered\n" twice, once when eval()ed, and a second time
> when handler() is called.  But you're not calling handler() a second
> time, you've got a bearword "Foo::handler" there, not a sub call.  Try
> adding some parens:
> 
>    Foo::Handler();

oops, my bad. so we need a special block which doesn't behave like a 
block but still can be called. Is it possible to adjust the scope of the 
code so when a compiler encounters a nested block/sub on the first 
level, we tell it using some low level magic, that in fact it's on the 
top level and not nested in the sub? something like this:

FLAT {
   #  the original script's code goes here
}


&FLAT;

and FLAT is a magic sub, which makes the code inside it call-able, but 
at the same time this code doesn't know that it's inside a sub?



-- 


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: cvs commit: modperl-2.0/ModPerl-Registry TODO

Posted by Barrie Slaymaker <ba...@slaysys.com>.
On Mon, Oct 22, 2001 at 10:46:04PM +0800, Stas Bekman wrote:
> 
> It works for me:
> 
> my $package = << 'END';
> package Foo ;
> 
>     enter:
>         print "entered\n" ;
> 
>     sub handler { goto enter }
> 
>     1 ;
> END
> 
> eval $package;
> Foo::handler;
> 
> prints:
> 
> entered

It should print "entered\n" twice, once when eval()ed, and a second time
when handler() is called.  But you're not calling handler() a second
time, you've got a bearword "Foo::handler" there, not a sub call.  Try
adding some parens:

   Foo::Handler();

- Barrie

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: cvs commit: modperl-2.0/ModPerl-Registry TODO

Posted by Stas Bekman <st...@stason.org>.
Barrie Slaymaker wrote:

> On Mon, Oct 22, 2001 at 08:33:49AM -0000, stas@apache.org wrote:
> 
>>   
>>  +- the closure issue:
>>  +  there was a suggestion from raptor to use goto() to leave the code
>>  +  unwrapped in the sub handler, which will solve the closure problem,
>>  +  but the problem is that once you leave a subroutine with goto() you
>>  +  cannot return, because you aren't in the sub anymore.
>>
> 
> The issue I saw with this was that the top-level code outside the subs
> in a module is unreachable (I suspect it's freed, but have no clue)
> after the module exits.  So, in something like
> 
>    package Foo ;
> 
>    enter:
>        print "entered\n" ;
> 
>    sub handler { goto enter }
> 
>    1 ;
> 
> , by the time you can call handler(), the label "enter" is no longer
> reachable.  I suspect it's because the top-level opcodes in a module are
> all freed after it is eval()ed.

It works for me:

my $package = << 'END';
package Foo ;

    enter:
        print "entered\n" ;

    sub handler { goto enter }

    1 ;
END

eval $package;
Foo::handler;

prints:

entered

The problem I see is not being able to do return(), since once I leave 
the sub's scope with goto(), I cannot get back to complete 'return 
Apache::OK'. Hmm, may be some XS black magic is possible here.


_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org