Subject: | REPL context not quite the same as script context |
I just ran into a subtle difference between
running in a perl script or in the REPL.
Devel::REPL, by default, forces list context
on the code being run, i.e.:
sub checkcontext {
if (wantarray) {
print "list context\n";
} elsif (defined wantarray) {
print "scalar context\n";
} else {
print "void context\n";
}
}
sub tryit {
checkcontext;
return 1;
}
checkcontext();
tryit();
When run as a program outputs:
void context
void context
But when cut an pasted into an re.pl session
the result is:
$ checkcontext();
list context
1
$ tryit();
void context
1
In addition, there is a problem with the DDS
output if the line being executed has a void
return, e.g.:
sub tryit {
checkcontext;
return;
}
When run in re.pl yields this:
$ tryit
void context
No arguments! at /home/chm/perl/lib/Devel/REPL/Plugin/DDS.pm line 17
Error! - Can't use string ("1") as an ARRAY ref while "strict refs" in
use at /usr/lib/perl5/site_perl/5.10/i686-cygwin/Data/Dump/Streamer.pm
line 1363.
I'm not sure what the best fix would be.
Documentation would help. It would be
nice if the REPL context better matched
the context from a perl program.
The DDS display "noise" when there is a
void return is a bug. I took a quick look
and didn't go futher since the code was
tricky and I did not wish to break anything.