Glad to hear that you got test code working. You are now well on your way!

Yes, putting package TEST_GIZMO inside of file TEST_GIZMO.pm would be the normal way. It is possible to have multiple packages within one file. The package is a name space. For what you are doing, that isn't necessary and can get confusing.

I would recommend that you put some sort of test function within the package. In one of my libraries, I just put sub test{} in every .pm file and of course didn't export the name "test" as every module has a test sub and the names would conflict. Then to test my library, I just call with the fully qualified name TEST_GIZMO::test; ModuleB::test;, etc. on all the .pm files. It is really handy to have the name of the file the same as package inside.

You will see that the .pm file can be run just like a .pl file. So you can have some sort of thing like "test if DEBUG"; DEBUG is a const flag. Anyway the idea is to get the package working with its own test routine before you start calling it from other programs.

You should consider your naming convention for your packages. You don't want to use names that might conflict with CPAN packages, etc. Say you've got some project TLA, then you could use TLA_Parse for say the parsing routines for project TLA. You'll have to decide what makes sense for whatever it is that you are doing.


In reply to Re^3: Calling Subroutines of package from another program? by Marshall
in thread Calling Subroutines of package from another program? by anbutechie

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.