perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn <gs-lists-modp...@gluelogic.com>
Subject Re: [MP2] eval and exit(0) : problem
Date Mon, 03 May 2004 17:42:50 GMT
On Mon, May 03, 2004 at 07:17:54PM +0200, Arnaud Blancher wrote:
> Stas Bekman a ?crit :
> 
> >Arnaud Blancher wrote:
> >
> >>Stas Bekman a ?crit :
> >>
> >>>ydnar wrote:
> >>>
> >>>>The eval() is unecessary. The named sub can be used:
> >>>>
> >>>>&$func(); 
> >>>
> >>>
> >>>
> >>yes but not with
> >> use strict
> >>...
> >
> >
> >try:
> >
> >  {
> >    no strict 'refs';
> >    &$func();
> >  }
> 
> 
> yes, it's work.
> i'don't realy like this solution, just because i always  try to use 'use 
> strict'
> to avoid problem with mod_perl !!!!

As Stas mentioned previously, you should be using coderefs: $func->()
instead of eval() with &$func().   If you use eval () with &$func(),
then I think you are bypassing some compile-time 'strict' checks on
that code.  If you want the compiler to enforce maximum strictness
(a good thing), and you always try to 'use strict', as you say above,
then you should be using coderefs instead of &$func().  An example
will better illustrate proper usage:

e.g. if you have the subroutines

sub routine_1 { ... }
sub routine_2 { ... }

then instead of doing:

my $func = 'routine_1';
[ ... ]
&$func();

try the following:

my $func = \&routine_1;
[ ... ]
$func->();

That will compile cleanly with 'strict' in effect.

If you do not know the routine name in advance, then you can
create a hash of 'routine_name' => coderef and look up the
routines to get the proper coderef:

%valid_routines = ('routine_1'=>\&routine_1, 'routine_2'=>\&routine_2);

$func = $valid_routines{$routine_name} || die "invalid routine name";

OT for the mod_perl list, but HTH.
Cheers,
Glenn

> so, could you tell me if the final mp2, will have a solution for exit in 
> eval function ?
> in this case i'll wait and keep my complete 'use strict'
> in the other case .. may be i will change all my script, and lost a part 
> of 'strict'.
> 
> 
> Thanks
> Arnaud.
> 
> 
> >
> >FWIW, I find $func->() to be a more readable syntax.
> >
> >
> >>>You don't need to load anything. Indeed under mp2:
> >>>
> >>>  *CORE::GLOBAL::exit = \&ModPerl::Util::exit;
> >>>
> >>>And you don't need to load anything for this to work.
> >>>
> >>>in mp2 exit is implemented via a special die() call, therefore if 
> >>>you call it inside eval { } block (and eval "STRING" behaves 
> >>>identically) an exception is being thrown, but caught by eval.
> >>
> >>
> >>
> >>
> >>for me, both solution don't work :-((
> >>maybe me installation is wrong ...
> >>the output is always the sum of &first &second
> >
> >
> >You mean one solution. Indeed, I tried it and it doesn't, since $@ is 
> >set to '', which is the same as if eval {} didn't die.
> >
> >You didn't try the second solution: CORE::exit(0), but you probably 
> >don't want to use it as it's not efficient. But it'll work exactly as 
> >mod_cgi does.
> >
> >I consider the inability to exit when called from eval as a problem, 
> >so we need to think of finding a better way to emulate 
> >exit-but-don't-exit functionality.
> 
> 
> 
> 
> -- 
> Report problems: http://perl.apache.org/bugs/
> Mail list info: http://perl.apache.org/maillist/modperl.html
> List etiquette: http://perl.apache.org/maillist/email-etiquette.html

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Mime
View raw message