New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require stringifies code references in tied @INC #8710
Comments
From haj@oook.m.uunet.deThis is a bug report for perl from haj@oook.m.uunet.de, require stringifies code references in @INC iff @INC is tied Summary: I can add a code reference to @INC, and I can tie @INC to a Demo 1 shows the simple use of a code reference in @INC, which works. use has the same problem but makes the demo unwieldier because I'd Demo 1: I am monitoring 'use' and 'require' usage by prepending a sub stop_here { die "Stopped before using '$_[1]'!\n"; } Demo 2: As above, but @INC is being tied. This should behave like sub stop_here { die "Stopped before using '$_[1]'!\n"; } sub watch_it { ### tie @INC Demo 3: To prove that the code reference is interpreted as a string, I sub stop_here { die "Stopped before using '$_[1]'!\n"; } sub watch_it { ### tie @INC Demo 4: Instead of using require, I am iterating through @INC by sub stop_here { die "Stopped before using '$_[1]'!\n"; } sub watch_it { ### tie @INC Flags: Site configuration information for perl v5.8.7: Configured by gerrit at Fri Dec 30 02:40:15 2005. Summary of my perl5 (revision 5 version 8 subversion 7) configuration: Locally applied patches: @INC for perl v5.8.7: Environment for perl v5.8.7: |
From rick@bort.caOn Dec 11 2006, haj@oook.m.uunet.de wrote:
The following patch fixes this. -- Inline Patchdiff -pruN perl-current/pp_ctl.c perl-current-dev/pp_ctl.c
--- perl-current/pp_ctl.c 2006-12-01 17:54:37.000000000 -0500
+++ perl-current-dev/pp_ctl.c 2006-12-15 14:51:30.000000000 -0500
@@ -3150,6 +3150,8 @@ PP(pp_require)
for (i = 0; i <= AvFILL(ar); i++) {
SV * const dirsv = *av_fetch(ar, i, TRUE);
+ if (SvTIED_mg((SV*)ar, PERL_MAGIC_tied))
+ mg_get(dirsv);
if (SvROK(dirsv)) {
int count;
SV **svp;
diff -pruN perl-current/t/op/inccode-tie.t perl-current-dev/t/op/inccode-tie.t
--- perl-current/t/op/inccode-tie.t 1969-12-31 19:00:00.000000000 -0500
+++ perl-current-dev/t/op/inccode-tie.t 2006-12-15 14:48:53.000000000 -0500
@@ -0,0 +1,15 @@
+#!./perl
+
+# Calls all tests in op/inccode.t after tying @INC first.
+
+use Tie::Array;
+my @orig_INC = @INC;
+tie @INC, 'Tie::StdArray';
+@INC = @orig_INC;
+for my $file ('./op/inccode.t', './t/op/inccode.t', ':op:inccode.t') {
+ if (-r $file) {
+ do $file;
+ exit;
+ }
+}
+die "Cannot find ./op/inccode.t or ./t/op/inccode.t\n";
diff -pruN perl-current/t/op/inccode.t perl-current-dev/t/op/inccode.t
--- perl-current/t/op/inccode.t 2006-11-08 10:35:31.000000000 -0500
+++ perl-current-dev/t/op/inccode.t 2006-12-15 14:53:06.000000000 -0500
@@ -202,10 +202,12 @@ is( $ret, 'abc', 'do "abc.pl" sees retur
{
my $filename = $^O eq 'MacOS' ? ':Foo:Foo.pm' : './Foo.pm';
- local @INC;
+ #local @INC; # local fails on tied @INC
+ my @old_INC = @INC; # because local doesn't work on tied arrays
@INC = sub { $filename = 'seen'; return undef; };
eval { require $filename; };
is( $filename, 'seen', 'the coderef sees fully-qualified pathnames' );
+ @INC = @old_INC;
}
exit if $minitest; |
From rick@bort.ca41071.patchdiff -pruN perl-current/pp_ctl.c perl-current-dev/pp_ctl.c
--- perl-current/pp_ctl.c 2006-12-01 17:54:37.000000000 -0500
+++ perl-current-dev/pp_ctl.c 2006-12-15 14:51:30.000000000 -0500
@@ -3150,6 +3150,8 @@ PP(pp_require)
for (i = 0; i <= AvFILL(ar); i++) {
SV * const dirsv = *av_fetch(ar, i, TRUE);
+ if (SvTIED_mg((SV*)ar, PERL_MAGIC_tied))
+ mg_get(dirsv);
if (SvROK(dirsv)) {
int count;
SV **svp;
diff -pruN perl-current/t/op/inccode-tie.t perl-current-dev/t/op/inccode-tie.t
--- perl-current/t/op/inccode-tie.t 1969-12-31 19:00:00.000000000 -0500
+++ perl-current-dev/t/op/inccode-tie.t 2006-12-15 14:48:53.000000000 -0500
@@ -0,0 +1,15 @@
+#!./perl
+
+# Calls all tests in op/inccode.t after tying @INC first.
+
+use Tie::Array;
+my @orig_INC = @INC;
+tie @INC, 'Tie::StdArray';
+@INC = @orig_INC;
+for my $file ('./op/inccode.t', './t/op/inccode.t', ':op:inccode.t') {
+ if (-r $file) {
+ do $file;
+ exit;
+ }
+}
+die "Cannot find ./op/inccode.t or ./t/op/inccode.t\n";
diff -pruN perl-current/t/op/inccode.t perl-current-dev/t/op/inccode.t
--- perl-current/t/op/inccode.t 2006-11-08 10:35:31.000000000 -0500
+++ perl-current-dev/t/op/inccode.t 2006-12-15 14:53:06.000000000 -0500
@@ -202,10 +202,12 @@ is( $ret, 'abc', 'do "abc.pl" sees retur
{
my $filename = $^O eq 'MacOS' ? ':Foo:Foo.pm' : './Foo.pm';
- local @INC;
+ #local @INC; # local fails on tied @INC
+ my @old_INC = @INC; # because local doesn't work on tied arrays
@INC = sub { $filename = 'seen'; return undef; };
eval { require $filename; };
is( $filename, 'seen', 'the coderef sees fully-qualified pathnames' );
+ @INC = @old_INC;
}
exit if $minitest;
|
The RT System itself - Status changed from 'new' to 'open' |
From @smpetersOn Fri Dec 15 20:29:00 2006, rickdelaney wrote:
Thanks! I applied this patch as change #29584. |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#41071 (status was 'resolved')
Searchable as RT41071$
The text was updated successfully, but these errors were encountered: