Skip Menu |

This queue is for tickets about the Eval-Util CPAN distribution.

Report information
The Basics
Id: 124747
Status: resolved
Priority: 0/
Queue: Eval-Util

People
Owner: Nobody in particular
Requestors: haarg [...] haarg.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Difference from $^S
How is the inside_eval function different from testing the $^S variable?
On Fri, 9 Mar 2018 20:20:13 GMT, haarg wrote: Show quoted text
> How is the inside_eval function different from testing the $^S variable?
There's no difference, I was simply not aware of $^S :-( I guess I could modify Eval::Util to return an integer that tells the level of eval one is in. That would add something.
On Fri Mar 09 15:20:13 2018, haarg wrote: Show quoted text
> How is the inside_eval function different from testing the $^S variable?
They differ in various subtle ways (all examples with 5.12.4): Compliing main program (__DIE__): $ perl -Ilib -MEval::Util=inside_eval -le 'BEGIN { $SIG{__DIE__} = sub { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval } } $a+' $^S: undef inside_eval: 0 syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. Compiling module (__DIE__): $ echo '$a+'>SyntaxError.pm $ perl -I. -Ilib -MEval::Util=inside_eval -le 'BEGIN { $SIG{__DIE__} = sub { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval } } require SyntaxError' $^S: 0 inside_eval: 0 syntax error at SyntaxError.pm line 1, at EOF Compilation failed in require at -e line 1. Dying in module’s main CV: $ echo 'die'>Die.pm bash-3.2$ perl -Ilib -MEval::Util=inside_eval -le 'BEGIN { $SIG{__DIE__} = sub { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval } } require Die' $^S: 0 inside_eval: 1 $^S: 0 inside_eval: 0 Died at Die.pm line 1. Compilation failed in require at -e line 1. (The second invocation is after require() re-throws the error.) Inside string eval: $ perl -Ilib -MEval::Util=inside_eval -le 'eval q{ print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval }' $^S: 1 inside_eval: 1 Inside blocky eval: $ perl -Ilib -MEval::Util=inside_eval -le 'eval { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval }' $^S: 1 inside_eval: 1 Die inside eval: $ perl -Ilib -MEval::Util=inside_eval -le 'BEGIN { $SIG{__DIE__} = sub { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval } } eval "die"' $^S: 1 inside_eval: 1 BEGIN block in main program: $ perl -Ilib -MEval::Util=inside_eval -le 'BEGIN { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval }' $^S: undef inside_eval: 1 BEGIN block in module: $ echo 'BEGIN { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval }'>Begin.pm $ perl -Ilib -MEval::Util=inside_eval -le 'require Begin' $^S: undef inside_eval: 1 Begin.pm did not return a true value at -e line 1. BEGIN block in string eval: $ perl -Ilib -MEval::Util=inside_eval -le 'eval q|BEGIN { print "\$^S: ", $^S // "undef"; print "inside_eval: ", inside_eval }|' $^S: undef inside_eval: 1 This means that for the various cases where $^S returns undef, you can use inside_eval to tell whether errors will be caught.
On Sun Mar 11 16:49:15 2018, SPROUT wrote: Show quoted text
> This means that for the various cases where $^S returns undef, you can > use inside_eval to tell whether errors will be caught.
I take that back. It’s just as useless as $^S when used from a BEGIN block.
I'm closing this ticket for now. Documentation has been added regarding $^S as well more functions have been added.