For your first point, you should read this thread on code reuse and method sharing, there are several ideas that are discussed for sharing objects through utility classes and superclasses.

For your second point, why not just have a MyPackage::Config file? Just something simple like this should work:

use MyPackage::Config; my $cgi_url = MyPackage::Config->cgi_url;
On the one had it may seem like overkill to make a module just for just reading config files, but I've done that before and I've found that abstracting out the reading/writing of configuration files makes your program read well. It also separates your configuration file format out, so that if you ever decide to change from a require'd file, then you only have to change that in one place. I personally think that requiring or eval'ing code in that manner is a bad idea, but that's a separate discussion.

Even better, once you make that configuration file object, you can share it using whatever method you use to share HTML::Template objects from your first question. :)

I actually think your third question may be answered in the linked thread as well. That thread is actually more pertinent to this question than the first.


In reply to Re: Packaging up my code sensibly by biosysadmin
in thread Packaging up my code sensibly by punkish

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.