Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Subroutine exec redefined warning with perl 5.12.2

Reply
Thread Tools

Subroutine exec redefined warning with perl 5.12.2

 
 
Marc Girod
Guest
Posts: n/a
 
      02-14-2011
Hello,

I installed Strawberry perl 5.12.2 on my new laptop and started to
install my modules on it.
And I met some surprises. I'll mention 3, but the first is the one
that bothers me for now.

1. I got a new warning, and I'd like to understand whether it displays
a yet unknown problem (with perl up to 5.10) or should just be
silenced (with the next question of how?)

The warning is:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852.

I get it in running a command line involving ClearCase::Wrapper::MGi.
This is hard to reproduce without ClearCase, even if the modules are
all on CPAN.
I tried to extract the significant code, but could not reproduce the
symptom.
So, here is my failed attempt at rproducing.
Could you please help me guessing what I could add to reproduce the
symptom, i.e. explain me what precisely it warns against?
There is indeed a redefinition of exec on line 852 of Argv.pm, but I
cannot see how it differes from the one below.

#!/usr/bin/perl

use warnings;
use strict;

package Foo;

sub exec {
print "overloaded in Foo\n";
}
sub new {
return bless {}, __PACKAGE__;
}

package Bar;
our @ISA = qw(Foo);

sub exec {
my $self = shift;
print "overloaded in Bar\n";
return $self->SUPER::exec;
}
sub new {
return bless {}, __PACKAGE__;
}

package main;
my $bar = new Bar;
$bar->exec;
exit 0;

This works the same on 5.12 as on 5.10:

$ ~/tmp/execdemo
overloaded in Bar
overloaded in Foo



2. Running: 'perl Makefile.PL' for all the modules I have tried
produces makefiles with a systematic syntax error:
double opening braces instead of single ones.

Running the following solves the problem:

W:\atcctest\Clone>perl -pi.bak -e "s/{{/{/g" Makefile



3. I fail to build the Clone package (from CPAN) with the following
error:

W:\atcctest\Clone>gmake
Skip blib\lib\Clone.pm (unchanged)
gcc -c -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -
DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-
bitfields -DPERL_MSVCRT_READFIX -O3 -DVERSION=\"0.28\" -DXS_VERSION=
\"0.28\" "-IC:\strawberry\perl\lib\CORE" Clone.c
Clone.xs: In function 'sv_clone':
Clone.xs:160: error: duplicate case value
Clone.xs:154: error: previously used here
gmake: *** [Clone.o] Error 1

Thanks,
Marc
 
Reply With Quote
 
 
 
 
Marc Girod
Guest
Posts: n/a
 
      02-14-2011
On Feb 14, 12:14*pm, Marc Girod <(E-Mail Removed)> wrote:

> Clone.xs: In function 'sv_clone':
> Clone.xs:160: error: duplicate case value
> Clone.xs:154: error: previously used here


BTW, this isn't true:

W:\atcctest\Clone>perl -nle "print if $. == 154 or $. == 160" Clone..xs
case SVt_IV: /* 1 */
case SVt_RV: /* 3 */

This is version 0.28.

Marc
 
Reply With Quote
 
 
 
 
C.DeRykus
Guest
Posts: n/a
 
      02-15-2011
On Feb 14, 4:14*am, Marc Girod <(E-Mail Removed)> wrote:
> Hello,
>
> I installed Strawberry perl 5.12.2 on my new laptop and started to
> install my modules on it.
> And I met some surprises. I'll mention 3, but the first is the one
> that bothers me for now.
>
> 1. I got a new warning, and I'd like to understand whether it displays
> a yet unknown problem (with perl up to 5.10) or should just be
> silenced (with the next question of how?)
>
> The warning is:
>
> Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
> 852.
>
> I get it in running a command line involving ClearCase::Wrapper::MGi.
> This is hard to reproduce without ClearCase, even if the modules are
> all on CPAN.
> I tried to extract the significant code, but could not reproduce the
> symptom.
> So, here is my failed attempt at rproducing.
> Could you please help me guessing what I could add to reproduce the
> symptom, i.e. explain me what precisely it warns against?
> There is indeed a redefinition of exec on line 852 of Argv.pm, but I
> cannot see how it differes from the one below.
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> package Foo;
>
> sub exec {
> * print "overloaded in Foo\n";}
>
> sub new {
> * return bless {}, __PACKAGE__;
>
> }
>
> package Bar;
> our @ISA = qw(Foo);
>
> sub exec {
> * my $self = shift;
> * print "overloaded in Bar\n";
> * return $self->SUPER::exec;}
>
> sub new {
> * return bless {}, __PACKAGE__;
>
> }
>
> package main;
> my $bar = new Bar;
> $bar->exec;
> exit 0;
>
> This works the same on 5.12 as on 5.10:
>
> $ ~/tmp/execdemo
> overloaded in Bar
> overloaded in Foo
>


But AFAIK a "subroutine redefined..." occurs
only if a sub is redefined within a class -
not because there are sub's of the same name
in its inheritance tree.

The only workaround is mentioned here:

perl -Mdiagnostics=-verbose -wlE
"BEGIN { $diagnostics:EBUG = 1 };
sub x{say 'first x'};
sub x{say 'second x'};"

DESCRIPTION OF DIAGNOSTICS
...

Trappable errors may be trapped using the
eval operator. See perlfunc/eval. In
almost all cases, warnings may be selectively
disabled or promoted to fatal errors using the
warnings pragma.
See warnings.

Subroutine x redefined at -e line 1 (#1)
(W redefine) You redefined a subroutine.
To suppress this warning,

{
no warnings 'redefine';
eval "sub name { ... }";
}


....

--
Charles DeRykus
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      02-16-2011
On Feb 15, 10:00*pm, "C.DeRykus" <(E-Mail Removed)> wrote:

> But AFAIK a "subroutine redefined..." occurs
> only if a sub is redefined within a class -
> not because there are sub's of the same name
> in its inheritance tree.


This is surprising: there is only one redefinition of exec per class.
There are two in the hierachy classes with similar names: Argv and
ClearCase::Argv (of course, it would be a bug if it affected,and it
doesn't seem to).

> The only workaround is mentioned here:
>
> perl -Mdiagnostics=-verbose -wlE


Excellent! Thanks!

> * * Subroutine x redefined at -e line 1 (#1)
> * * (W redefine) You redefined a subroutine.
> * * *To suppress this warning,
>
> * * * * {
> * * * * no warnings 'redefine';
> * * * * eval "sub name { ... }";
> * * * * }


Thanks. Very useful indeed.
I do get a similar output with my script:

Subroutine exec redefined at C:/strawberry/perl/site/lib/Argv.pm line
852 (#2)
(W redefine) You redefined a subroutine. To suppress this
warning, say

Now, this doesn't tell where #1 would be... (which I cannot find).
Thanks again.
I continue my investigations.

Marc
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      02-16-2011
On Feb 16, 11:40*am, Marc Girod <(E-Mail Removed)> wrote:

> Now, this doesn't tell where #1 would be... (which I cannot find).


Sorry, I understand now that #1 was unrelated:

Name "main::rem" used only once: possible typo at
c:\strawberry\perl\site\bin\cleartool.bat line 1 (#1)

A hack to get the Perl script run as a Windows batch.
But no clue about where the 'first definition' might be...

Marc
 
Reply With Quote
 
Marc Girod
Guest
Posts: n/a
 
      02-16-2011
On Feb 16, 11:40*am, Marc Girod <(E-Mail Removed)> wrote:

> To suppress this warning, say


{
no warnings 'redefine';
eval "sub name { ... }";
}

Unfortunately, this is not very practical...
I used actually: eval qq(sub name { ... });
It results in a large batch of errors for all the variables used:

Variable "@cmd" is not imported at C:/strawberry/perl/site/lib/Argv.pm
line 854.
....

Putting: no warnings 'redefine';
at file scope is likely to be *very* counterproductive...

Marc
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array.sort when it's items are String inheritors with redefined <=> works like if not redefined MiG Ruby 8 10-19-2005 03:48 PM
subroutine redefined warning jyothsna Perl Misc 3 10-04-2005 03:53 PM
Removing "warning: method redefined" Brian Takita Ruby 4 07-08-2005 04:36 PM
'Subroutine redefined' annoyance bill Perl Misc 10 02-08-2005 08:51 PM
delegate.rb:110: warning: method redefined; discarding old __getobj__ Simon Strandgaard Ruby 0 02-23-2004 06:28 PM



Advertisments