There's plainly something I don't understand. I have a file which
contains four packages; the first is a base class and the other three are subclasses of it. The code runs fine but I'm getting warnings that the subroutines are redefined; I thought that was the whole purpose of subclassing! I know I can put "no warnings redefine", but should I have
to?
#!/usr/bin/perl
use strict;
use warnings;
use 5.016;
package A;
sub new{
print "This is the new method for A\n";
}
sub doodle{
print "This is the doodle method for A\n";
}
1;
package B;
use parent 'A';
sub new{
print "This is a subclassed method for B\n";
}
1;
# perl -c A.pm
Subroutine new redefined at /home/henry/Perl/tryout/A.pm line 9.
Subroutine doodle redefined at /home/henry/Perl/tryout/A.pm line 13. Subroutine new redefined at A.pm line 23.
A.pm syntax OK
PS: there's something really weird going on, because "doodle" isn't even being subclassed and yet it still gets a warning.
--
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England
There's plainly something I don't understand. I have a file which
contains four packages; the first is a base class and the other three are subclasses of it. The code runs fine but I'm getting warnings that the subroutines are redefined; I thought that was the whole purpose of subclassing! I know I can put "no warnings redefine", but should I have
to?
#!/usr/bin/perl
use strict;
use warnings;
use 5.016;
package A;
sub new{
print "This is the new method for A\n";
}
sub doodle{
print "This is the doodle method for A\n";
}
1;
package B;
use parent 'A';
sub new{
print "This is a subclassed method for B\n";
}
1;
# perl -c A.pm
Subroutine new redefined at /home/henry/Perl/tryout/A.pm line 9.
Subroutine doodle redefined at /home/henry/Perl/tryout/A.pm line 13. Subroutine new redefined at A.pm line 23.
A.pm syntax OK
PS: there's something really weird going on, because "doodle" isn't even being subclassed and yet it still gets a warning.
--
Henry Law n e w s @ l a w s h o u s e . o r g
Manchester, England
There's plainly something I don't understand.
I have a file which contains four packages; the first is a base class
and the other three are subclasses of it. The code runs fine but I'm
getting warnings that the subroutines are redefined; I thought that
was the whole purpose of subclassing!
I know I can put "no warnings redefine", but should I have to?
PS: there's something really weird going on, because "doodle" isn't
even being subclassed and yet it still gets a warning.
with <OOucnQu3LuKfnC__nZ2dnZeNn_XNnZ2d@giganews.com> Henry Law wrote:
I know I can put "no warnings redefine", but should I have to?
Well you have options:
* Do it properly -- one '.pm', one 'package'. Make ovid happy.
* Plug warnings with "no warnings qw/ redefine /". Make perl happy.
* Manipulate '@ISA' directly. Shoot yourself in foot sometime later.
* Search CPAN, probably there is something in support of Koo-Koo
modules, but I don't have any keywords to start with. Make yourself
busy.
* Did I miss something?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 360 |
Nodes: | 16 (2 / 14) |
Uptime: | 131:06:09 |
Calls: | 7,686 |
Files: | 12,828 |
Messages: | 5,711,301 |