Menu

Bogus "redefined" warnings f...

Help
2011-01-03
2013-05-20
  • Peter Valdemar Mørch

    Being new to Eclipse (not perl) I'm seeing 730 warnings from my .pm files. EPIC seems to test them like so:

    perl -w -c Foo.pm
    

    But isn't this more appropriate for modules?

    perl -w -c -MFoo -e ''
    

    For example, I created this in a new project in a new workspace as Redefined.pm:

    package Redefined;
    # Here is a real warning:
    my $var = 1;
    my $var = 2;
    sub foo {
        print "This is Redefined::foo\n";
    }
    use constant FOO => 1;
    package Redefined::Sub;
    use base qw(Redefined);
    sub foo {
        print "This is Redefined::Sub::foo\n";
    }
    1;
    

    With

    perl -w -c -MRedefined -e ''
    

    , I get:

    "my" variable $var masks earlier declaration in same scope at Redefined.pm line 5.
    

    which expect. However with

    perl -w -c Redefined.pm
    

    , I get:

    "my" variable $var masks earlier declaration in same scope at Redefined.pm line 5.
    "my" variable $var masks earlier declaration in same scope at Redefined.pm line 5.
    Subroutine foo redefined at Redefined.pm line 7.
    Constant subroutine Redefined::FOO redefined at /usr/share/perl/5.10/constant.pm line 115.
    Subroutine foo redefined at Redefined.pm line 16.
    Redefined.pm syntax OK
    

    Are these warnings valid in your opinion? I'd like not to be forced to have many tiny .pm files - one for each class. Many of them are *tiny*. Is there any way for me to avoid these warnings so  I can see other warnings?

     
  • Jan Ploski

    Jan Ploski - 2011-01-04

    I think the warnings are valid. "use base" seems to assume that the base class is in a different file - it is equivalent to BEGIN { require Redefined; @ISA = qw(Redefined); }, which will produce the same double warning at "require". A workaround would be to simply assign @ISA = qw(Redefined).

    Your proposed way of syntax checking sounds unreliable because it is not clear which package name should appear after -M if the target .pm file contained n different packages. I'm also not sure whether it would catch all warnings, though I don't have a counterexample.

     
  • Oliver Trosien

    Oliver Trosien - 2011-01-04

    You don't get this error if you code it like that. is this a perl bug?

    package Redefined::Base;

    … your base code

    package Redefined::Sub;

    .. your subclass code

    1:

     
  • Oliver Trosien

    Oliver Trosien - 2011-01-04

    ok, sorry.. jploski was faster, and I'll agree to what he wrote. Use "use base" only if you put your modules in seperate files. otherwise use @ISA = qw(…)

     

Log in to post a comment.