Subject: | Subroutine redefined warnings when -W is enabled in perl 5.8 |
Test command to replicate bug in perl 5.8: perl -cW -e 'use Cwd'
When using Cwd in a script where Perl's -W option (not -w) is turned
on, messages are reported saying (on Windows XP):
Subroutine Cwd::fastcwd redefined at C:/Perl/lib/Cwd.pm line 701.
Subroutine Cwd::getcwd redefined at C:/Perl/lib/Cwd.pm line 701.
Subroutine Cwd::abs_path redefined at C:/Perl/lib/Cwd.pm line 701.
or (on Solaris 10):
Subroutine Cwd::fastcwd redefined at /usr/perl5/5.8.4/lib/sun4-solaris-
64int/XSLoader.pm line 91.
Both or the above are Perl 5.8.x. These messages are not reported on a
Solaris 8 machine running Perl 5.6.0. (See full version info below.)
I was able to come up with a fix that seems to work well. I've
attached the original Cwd.pm modules as Cwd.orig.pm and my fixed
version as Cwd.new.pm. The only change is a new line of code inserted
at line 700 (borrowing an idea from Exporter::Heavy):
local $SIG{__WARN__} = sub { my $text = shift; warn $text unless ($text
=~ /^Subroutine Cwd::\S+ redefined at /); };
I tried several other ways to disable these warnings, but was not
successful. This is the only way that worked for me.
Adding "no warnings 'redefine';" or "no warnings;" instead of the above
each had no effect. I'm not sure why. Ideally, they should turn off
the warnings. In simple command line tests, I was able to get them to
work as I expected them to. Here's one example (that tries to mimic
what is happening with Cwd):
C:\>perl -e "BEGIN{package foo; use strict; use warnings; sub getcwd
{print 'a'} my $z=sub{print 'b'}; {no strict 'refs'; no warnings; my
$name='getcwd'; *{$name}=\&{$z};}} foo::getcwd();"
Perl versions:
==========
Windows XP
==========
C:\>perl -v
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 18 registered patches, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Binary build 813.2 [266744] provided by ActiveState
http://www.ActiveState.com
Built Aug 9 2006 00:59:31
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.org/, the Perl Home
Page.
==========
Solaris 10
==========
# perl -v
This is perl, v5.8.4 built for sun4-solaris-64int
(with 29 registered patches, see perl -V for more detail)
Copyright 1987-2004, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.
==========
Solaris 8
==========
# perl -v
This is perl, v5.6.0 built for sun4-solaris-thread-multi
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2000, Larry Wall
Binary build 623 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 02:33:31 Dec 19 2001
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.
Subject: | Cwd.orig.pm |
Message body is not shown because it is too large.
Subject: | Cwd.new.pm |
Message body is not shown because it is too large.