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. Advertisements

  2. Marc Girod

    Marc Girod Guest

    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. Advertisements

  3. Marc Girod

    C.DeRykus Guest

    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 { ... }";
    }


    ....
     
    C.DeRykus, Feb 15, 2011
    #3
  4. Marc Girod

    Marc Girod Guest

    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).
    Excellent! Thanks!
    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

    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

    {
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.