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
FileCache only works in "main" package #7693
Comments
From @kaibolayThis is a bug report for perl from kai@bolay.de, ----------------------------------------------------------------- I As a workaround I temporarily switch to the "main" package when using $ cat FileCacheBug.pl use strict; eval { eval { no strict "refs"; if (!$@) { eval { no strict "refs"; if (!$@) { $ ./FileCacheBug.pl Flags: This perlbug was built using Perl v5.8.5 in the Red Hat build system. Site configuration information for perl v5.8.5: Configured by Red Hat, Inc. at Tue Oct 12 12:44:18 EDT 2004. Summary of my perl5 (revision 5 version 8 subversion 5) configuration: Locally applied patches: @INC for perl v5.8.5: Environment for perl v5.8.5: |
From @schwernOn Tue, Dec 07, 2004 at 10:45:16PM -0000, kai @ bolay. de wrote:
Unless I'm misunderstanding, this is not a bug in FileCache. This is how use Text::Soundex; package Foo; F000 Module will typically only export their functions into the current package. If you want to use FileCache or any module's functions in a package you
Add a "use File::Cache;" here and you're good.
-- |
The RT System itself - Status changed from 'new' to 'open' |
From @tamiasOn Wed, Dec 08, 2004 at 12:06:29AM -0500, Michael G Schwern wrote:
I was going to make the same suggestion, but I tried it, and it didn't Ronald |
From @schwernOn Wed, Dec 08, 2004 at 12:38:33AM -0500, Ronald J Kimball wrote:
Its line 1. The problem appears to be that its exporting to caller(1) not caller(0). -- |
From kane@xs4all.netOn Dec 8, 2004, at 7:09 AM, Michael G Schwern wrote:
I'll send a patch for use of Exporter + tests along this afternoon -- 'Real programmers use "cat > a.out"' CPANPLUS http://cpanplus.sf.net |
From kane@xs4all.netOn Dec 8, 2004, at 9:57 AM, Jos I. Boumans wrote:
Patch attached to make FileCache use Exporter, plus a new test file lib/FileCache/t/01open....................ok -- From kid's Superman costume for Halloween (stitched into the cape's CPANPLUS http://cpanplus.sf.net |
From kane@xs4all.netfilecache-exporter-[#32949].patch--- MANIFEST.org Wed Dec 8 11:02:20 2004
+++ MANIFEST Wed Dec 8 10:37:27 2004
@@ -1345,6 +1345,7 @@
lib/FileCache/t/03append.t See if FileCache works
lib/FileCache/t/04twoarg.t See if FileCache works
lib/FileCache/t/05override.t See if FileCache works
+lib/FileCache/t/06export.t See if FileCache exporting works
lib/File/CheckTree.pm Perl module supporting wholesale file mode validation
lib/File/CheckTree.t See if File::CheckTree works
lib/File/Compare.pm Emulation of cmp command
--- lib/FileCache.pm.org Wed Dec 8 10:10:12 2004
+++ lib/FileCache.pm Wed Dec 8 14:20:33 2004
@@ -84,15 +84,27 @@
# These are not C<my> for legacy reasons.
# Previous versions requested the user set $cacheout_maxopen by hand.
# Some authors fiddled with %saw to overcome the clobber on initial open.
-use vars qw(%saw $cacheout_maxopen);
+use vars qw(%saw $cacheout_maxopen @EXPORT);
my %isopen;
my $cacheout_seq = 0;
sub import {
my ($pkg,%args) = @_;
- $pkg = caller(1);
- *{$pkg.'::cacheout'} = \&cacheout;
- *{$pkg.'::close'} = \&cacheout_close;
+
+ # Not using Exporter is naughty.
+ # Also, using caller(1) is just wrong.
+ #$pkg = caller(1);
+ #*{$pkg.'::cacheout'} = \&cacheout;
+ #*{$pkg.'::close'} = \&cacheout_close;
+
+ # Use Exporter. %args are for us, not Exporter.
+ # Make sure to up export_to_level, or we will import into ourselves,
+ # rather than our calling package;
+ use base 'Exporter';
+ @EXPORT = qw[cacheout cacheout_close];
+
+ __PACKAGE__->export_to_level(1);
+ Exporter::import( $pkg );
# Truth is okay here because setting maxopen to 0 would be bad
return $cacheout_maxopen = $args{maxopen} if $args{maxopen};
diff -u /dev/null lib/FileCache/t/06export.t
--- /dev/null Wed Dec 8 11:05:55 2004
+++ lib/FileCache/t/06export.t Wed Dec 8 11:05:39 2004
@@ -0,0 +1,62 @@
+#!./perl
+BEGIN {
+ chdir 't' if -d 't';
+
+ #For tests within the perl distribution
+ @INC = '../lib' if -d '../lib';
+ END;
+
+ # Functions exported by FileCache;
+ @funcs = qw[cacheout cacheout_close];
+ $i = 0;
+
+ # number of tests
+ print "1..8\n";
+}
+
+# Test 6: Test that exporting both works to package main and
+# other packages. Now using Exporter.
+
+# First, we shouldn't be able to have these in our namespace
+# Add them to BEGIN so the later 'use' doesn't influence this
+# test
+BEGIN {
+ for my $f (@funcs) {
+ ++$i;
+ print 'not ' if __PACKAGE__->can($f);
+ print "ok $i\n";
+ }
+}
+
+# With an empty import list, we also shouldn't have them in
+# our namespace.
+# Add them to BEGIN so the later 'use' doesn't influence this
+# test
+BEGIN {
+ use FileCache ();
+ for my $f (@funcs) {
+ ++$i;
+ print 'not ' if __PACKAGE__->can($f);
+ print "ok $i\n";
+ }
+}
+
+
+# Now, we use FileCache in 'main'
+{ use FileCache;
+ for my $f (@funcs) {
+ ++$i;
+ print 'not ' if !__PACKAGE__->can($f);
+ print "ok $i\n";
+ }
+}
+
+# Now we use them in another package
+{ package X;
+ use FileCache;
+ for my $f (@main::funcs) {
+ ++$main::i;
+ print 'not ' if !__PACKAGE__->can($f);
+ print "ok $main::i\n";
+ }
+}
|
From @rgsJos I. Boumans wrote:
Thanks, applied as #23627. |
@rgs - Status changed from 'open' to 'resolved' |
@kaibolay - Status changed from 'resolved' to 'open' |
From @kaibolayThanks for the quick response(s)! Unfortunately the socond aspect of the bug is still there. I think it is # Open in their package. I attached a patch to your 06export.t which tries to show the problem. Here's the output when I run the patched test script with your patched 1..11 I guess the problems on line 162 and 165 in FileCache.pm should also be Thanks so much! |
From @kaibolaybug.patch*** 06export.t.org 2004-12-08 15:59:10.005377914 -0500
--- 06export.t 2004-12-08 15:56:34.527858529 -0500
***************
*** 1,4 ****
! #!./perl
BEGIN {
chdir 't' if -d 't';
--- 1,4 ----
! #!./perl -w
BEGIN {
chdir 't' if -d 't';
*************** BEGIN {
*** 8,17 ****
# Functions exported by FileCache;
@funcs = qw[cacheout cacheout_close];
$i = 0;
# number of tests
! print "1..8\n";
}
# Test 6: Test that exporting both works to package main and
--- 8,18 ----
# Functions exported by FileCache;
@funcs = qw[cacheout cacheout_close];
+
$i = 0;
# number of tests
! print "1..11\n";
}
# Test 6: Test that exporting both works to package main and
*************** BEGIN {
*** 39,44 ****
--- 40,54 ----
print 'not ' if __PACKAGE__->can($f);
print "ok $i\n";
}
+
+ ++$i;
+ my $file = "foo.$$.".time();
+ FileCache::cacheout $file; print $file "content"; close($file);
+ my $content;
+ if (open($file, "<", $file)) {local $/; $content=<$file>; close ($file);}
+ unlink($file);
+ print "not " if ($content ne "content");
+ print "ok $i\n";
}
*************** BEGIN {
*** 49,54 ****
--- 59,73 ----
print 'not ' if !__PACKAGE__->can($f);
print "ok $i\n";
}
+
+ ++$i;
+ my $file = "foo.$$.".time();
+ cacheout $file; print $file "content"; close($file);
+ my $content;
+ if (open($file, "<", $file)) {local $/; $content=<$file>; close ($file);}
+ unlink($file);
+ print "not " if ($content ne "content");
+ print "ok $i\n";
}
# Now we use them in another package
*************** BEGIN {
*** 59,62 ****
--- 78,90 ----
print 'not ' if !__PACKAGE__->can($f);
print "ok $main::i\n";
}
+
+ ++$main::i;
+ my $file = "foo.$$.".time();
+ cacheout $file; print $file "content"; close($file);
+ my $content;
+ if (open($file, "<", $file)) {local $/; $content=<$file>; close ($file);}
+ unlink($file);
+ print "not " if ($content ne "content");
+ print "ok $main::i\n";
}
|
From @schwern
This much at least is because FileCache::import has not yet been called When you do "use FileCache ()" import is not called so $cache_maxopen is |
From @schwern
The rest of this is because, I think, FileCache does not check to see if In your test you do this. cacheout $file; FileCache does not check to see if the file has gone away and try to This is separate from the exporting problem. |
From @kaibolayMichael G Schwern via RT wrote:
I think you're misreading my test script. The second (and third) What I do is: { my $file = "filename"; { my $file = "filename"; [...]
I don't think so. I think the "print() on unopened filehandle" is caused sub cacheout_open { Jos I. Boumans <kane@xs4all.net> replaced similar uses of caller(1) in I've updated my test script to use $file1, $file2, and $file3 as [kbolay@dose FileCacheBug]$ cat ./06export.t #For tests within the perl distribution # Functions exported by FileCache; $i = 0; # number of tests # Test 6: Test that exporting both works to package main and # First, we shouldn't be able to have these in our namespace # With an empty import list, we also shouldn't have them in ++$i; # Now, we use FileCache in 'main' ++$i; # Now we use them in another package ++$main::i; [kbolay@dose FileCacheBug]$ perl ./06export.t |
From @kaibolayMichael G Schwern via RT wrote: > The rest of this is because, I think, FileCache does not check to see if I think you're misreading my test script. The second (and third) What I do is: { my $file = "filename"; { my $file = "filename"; [...] > FileCache does not check to see if the file has gone away and try to I don't think so. I think the "print() on unopened filehandle" is caused sub cacheout_open { Jos I. Boumans <kane@xs4all.net> replaced similar uses of caller(1) in I've updated my test script to use $file1, $file2, and $file3 as [kbolay@dose FileCacheBug]$ cat ./06export.t #For tests within the perl distribution # Functions exported by FileCache; $i = 0; # number of tests # Test 6: Test that exporting both works to package main and # First, we shouldn't be able to have these in our namespace # With an empty import list, we also shouldn't have them in ++$i; # Now, we use FileCache in 'main' ++$i; # Now we use them in another package ++$main::i; [kbolay@dose FileCacheBug]$ perl ./06export.t |
From @schwernOn Mon, Dec 13, 2004 at 04:33:17PM -0500, Kai Bolay wrote:
But they're both set to the same *filename*. Therefore, without diving too
While I'm not sure the use of caller(1) is correct, I believe that to be
Try using a different *filename*. -- |
From @schwernOn Wed, Dec 15, 2004 at 01:54:37AM -0500, Kai Bolay wrote:
Wouldn't it be easier to get it to check first if the filehandle was -- |
From @kaibolayMichael G Schwern wrote: > On Mon, Dec 13, 2004 at 04:33:17PM -0500, Kai Bolay wrote: Ah. You're right! Sorry about getting confused. Maybe FileCache can be >> I don't think so. I think the "print() on unopened filehandle" is You're right. Thanks, Kai |
@smpeters - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#32949 (status was 'resolved')
Searchable as RT32949$
The text was updated successfully, but these errors were encountered: