Subroutine exec redefined warning with perl 5.12.2

Discussion in 'Perl Misc' started by Marc Girod, Feb 14, 2011.

  1. Marc Girod

    Marc Girod Guest

    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
     
    Marc Girod, Feb 14, 2011
    #1
    1. Advertising

  2. Marc Girod

    Marc Girod Guest

    gcc error in Clone (was: Subroutine exec...)

    On Feb 14, 12:14 pm, Marc Girod <> 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
     
    Marc Girod, Feb 14, 2011
    #2
    1. Advertising

  3. Marc Girod

    C.DeRykus Guest

    On Feb 14, 4:14 am, Marc Girod <> 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::DEBUG = 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
     
    C.DeRykus, Feb 15, 2011
    #3
  4. Marc Girod

    Marc Girod Guest

    On Feb 15, 10:00 pm, "C.DeRykus" <> 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
     
    Marc Girod, Feb 16, 2011
    #4
  5. Marc Girod

    Marc Girod Guest

    On Feb 16, 11:40 am, Marc Girod <> 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
     
    Marc Girod, Feb 16, 2011
    #5
  6. Marc Girod

    Marc Girod Guest

    On Feb 16, 11:40 am, Marc Girod <> 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
     
    Marc Girod, Feb 16, 2011
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Strandgaard
    Replies:
    0
    Views:
    105
    Simon Strandgaard
    Feb 23, 2004
  2. Brian Takita

    Removing "warning: method redefined"

    Brian Takita, Jul 8, 2005, in forum: Ruby
    Replies:
    4
    Views:
    103
    Brian Takita
    Jul 8, 2005
  3. MiG
    Replies:
    8
    Views:
    150
    Ryan Leavengood
    Oct 19, 2005
  4. bill

    'Subroutine redefined' annoyance

    bill, Feb 7, 2005, in forum: Perl Misc
    Replies:
    10
    Views:
    237
    Anno Siegel
    Feb 8, 2005
  5. jyothsna

    subroutine redefined warning

    jyothsna, Oct 4, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    227
Loading...

Share This Page