dcvr69 has asked for the wisdom of the Perl Monks concerning the following question:
Ok. I've been looking (perldoc/google/super search) for the right way to do this - right in the sense that I don't have to disable warnings to prevent the subroutine redefined messages.
I've reduced the problem to a very mininal test case:
package X; sub x { 1 } package X::Y; use base 'X'; 1;
This produces the following warning:
$ perl -cw X.pm Subroutine x redefined at /data/web/lib/X.pm line 3. X.pm syntax OK
Now, I (think I) understand why it's giving this error - because it's trying to use the base package when it hasn't actually finished loading the file the base package is in. Splitting the X::Y package into it's own file eliminates the problem.
The full code is a pair of Class::DBI classes for a master/detail pair of tables, and I'd prefer to keep them together in one file. Is there a "right" way to do that, and prevent the sub redefined warnings? If not, I can live with having 2 files (or N files later) rather than 1.
Humbly,Update: seems I missed the essential perldoc relevant to the problem (base). Simply defining a $VERSION for my base class prevents the sub-classes from doing 'require "X"' unnecessarily.
This works as intended:
package X; $VERSION = 0.01; sub x { 1 } package X::Y; use base 'X'; 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple packages in one file and subroutine redifned warnings
by japhy (Canon) on May 18, 2004 at 18:27 UTC | |
|
Re: multiple packages in one file and subroutine redifned warnings
by duff (Parson) on May 18, 2004 at 18:18 UTC | |
by dcvr69 (Beadle) on May 18, 2004 at 18:24 UTC |