develooper Front page | perl.perl5.porters | Postings from April 2003

Re: Core modules w/o "1;" [Was: Re: Pod::Man has no "1;"...]

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
April 1, 2003 11:53
Subject:
Re: Core modules w/o "1;" [Was: Re: Pod::Man has no "1;"...]
Message ID:
20030401215640.2d6843f5.rgarciasuarez@free.fr
Dan Kogai wrote:
> A ha!  Now I see. prior to #9579 eval() always eval() is always 
> evaluated in scalar context but after that eval() is smart enough to 
> check the context, including void context.

Right. eval("") should be forced in scalar context when used on a
require(), because require() should be forced in scalar context.
I applied the patch below :

Change 19126 by rgs@rgs-home on 2003/04/01 18:39:43

	Fix bug #21742. require should be always invoked in
	scalar context. This wasn't the case when called from
	an eval(""), because the void context doesn't propagate
	through the leaveeval op. Instead of making scalarvoid()
	handle OP_LEAVEEVAL -- this breaks AutoLoader -- implement
	a workaround in doeval().

Affected files ...

... //depot/perl/pp_ctl.c#351 edit
... //depot/perl/t/comp/require.t#24 edit

Differences ...

==== //depot/perl/pp_ctl.c#351 (text) ====

@@ -2884,7 +2884,13 @@
 	*startop = PL_eval_root;
     } else
 	SAVEFREEOP(PL_eval_root);
-    if (gimme & G_VOID)
+    if (gimme & G_VOID && ! PL_in_eval & EVAL_INREQUIRE)
+	/*
+	 * EVAL_INREQUIRE (the code is being required) is special-cased :
+	 * in this case we want scalar context to be forced, instead
+	 * of void context, so a proper return value is returned from
+	 * C<require> via this leaveeval op.
+	 */
 	scalarvoid(PL_eval_root);
     else if (gimme & G_ARRAY)
 	list(PL_eval_root);

==== //depot/perl/t/comp/require.t#24 (xtext) ====

@@ -11,8 +11,8 @@
 
 my $Is_EBCDIC = (ord('A') == 193) ? 1 : 0;
 my $Is_UTF8   = (${^OPEN} || "") =~ /:utf8/;
-my $total_tests = 23;
-if ($Is_EBCDIC || $Is_UTF8) { $total_tests = 20; }
+my $total_tests = 29;
+if ($Is_EBCDIC || $Is_UTF8) { $total_tests = 26; }
 print "1..$total_tests\n";
 
 sub do_require {
@@ -130,6 +130,22 @@
 sub dofile { do "bleah.do"; };
 print $x;
 
+# Test that scalar context is forced for require
+
+write_file('bleah.pm', <<'**BLEAH**'
+print "not " if !defined wantarray || wantarray ne '';
+print "ok $i - require() context\n";
+1;
+**BLEAH**
+);
+                              delete $INC{"bleah.pm"}; ++$::i;
+$foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
+@foo = eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
+       eval q{require bleah}; delete $INC{"bleah.pm"}; ++$::i;
+$foo = eval  {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
+@foo = eval  {require bleah}; delete $INC{"bleah.pm"}; ++$::i;
+       eval  {require bleah};
+
 # UTF-encoded things - skipped on EBCDIC machines and on UTF-8 input
 
 if ($Is_EBCDIC || $Is_UTF8) { exit; }
-- 
Unthinkable is not *NIX

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About