Open hexcoder- opened 4 months ago
The debugger itself historically didn't use strict, when it was re-worked and used strict itself, the eval context was modified to allow that.
I don't think we would change the default, but I could see adding an option to control it.
The DB::eval behaviour the debugger uses to compile and execute the code in the parent lexical scope doesn't appear to propagate strict from that scope.
It seems to use features (as in use feature '...'
) from the debugger scope too, which could be confusing, though the only case I can think of is switch:
$ ./perl -Ilib -Mfeature=switch -de 'print "Hello\n"'
Loading DB routines from perl5db.pl version 1.80
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(-e:1): print "Hello\n"
DB<1> x no warnings; do { given (1) { when (1) { say "One!" } } };
syntax error at (eval 9)[lib/perl5db.pl:742] line 2, near ") {"
Execution of (eval 9)[lib/perl5db.pl:742] aborted due to compilation errors.
at (eval 9)[lib/perl5db.pl:742] line 2.
eval 'no strict; ($@, $!, $^E, $,, $/, $\\, $^W) = @DB::saved;package main; $^D = $^D | $DB::db_stop;
no warnings; do { given (1) { when (1) { say "One!" } } };;
' called at lib/perl5db.pl line 742
DB::eval called at lib/perl5db.pl line 3444
DB::DB called at -e line 1
DB<2> x use feature "switch"; no warnings; do { given (1) { when (1) { say "One!" } } };
One!
0 1
DB<3>
Using switch in an x expression seems unlikely though.
Thanks, an option would be appreciated! I often use the debugger to evaluate small code snippets before doing a correction in my script. It would be really nice, if the evaluation would behave the same as the script run.
Module: perl5db.pl or DB.pm
Description
When starting the debugger with
perl -Mstrict -wde 1
the "use strict" has no effect on subsequent expressions used with the
x
command (e.g forDB::eval
):x join('', BARE, WORD)
->0 'BAREWORD'
This is in contrast WRT the same setup in an oneliner:
Steps to Reproduce
perl -Mstrict -wde 1
x join('', BARE, WORD)
gives0 'BAREWORD'
Expected behavior
When
use strict
is in effect, BAREWORDs should be errors also in evaluated expressions for consistency.Perl configuration