Well, that's all well and good, since it does solve the problem of making sure that the reference to %fields points to the one in the appropriate file, but it sort of recreates the original problem I was trying to solve.

The whole point of inheriting the constructor was that I had subclasses that were all using esentially the same code for a constructor, so why duplucate the code. If I made changes, I'd have to update each package, etc. Instead, inherit it. But that introduced the problem that started this thread.

Your solution creates an init method, which must now exist in the same file as the subclass, and thus much exist in the same file for each and every subclass. While it significantly reduces the amount of code that is reproduced in each module, it doesn't eliminate it entirely.

If I make init inheritable from the base clase though, then I run into the same problem again. The reference points to the hash in the wrong file. It seems to be a chicken and the egg problem. Perhaps file-scoped lexical isn't the right way to go, but then how else do I get the fields (a name I shall change now, thank you for the education) for each class set up if not through a file-scoped lexical?


In reply to Re: Re: Inheritence of a Constructor that uses a file-scoped lexical? by Orsmo
in thread Inheritence of a Constructor that uses a file-scoped lexical? by Orsmo

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.