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,

dcvr69

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;

In reply to multiple packages in one file and subroutine redefined warnings by dcvr69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.