1. See my response to #2.
  2. Yes - this is part of the interface that the module publishes to the rest of the world. In fact, it's the whole reason the module exists. You had the same thing in your initial version. Mine just makes it a little more explicit.
  3. use Foo ('bar', 'baz'); is actually* implemented internally as so:
    BEGIN { require 'Foo.pm'; Foo->import( 'bar', 'baz' ); }
    The command that brings a file into your code is "require". "use" wraps require and adds a little something to it. Now, in my code, Exporter goes ahead and provides a import() method for you, expecting to use the @EXPORT_OK array to find stuff to bring from use'd namespace to the use-r. That's how $data makes it over from test0 to main.
You might be confused by the funky syntax. That's because I'm doing an eval. You could replace the eval with the equivalent
(my $filename = $pm) =~ s{ :: }{ / }gx; require "${filename}.pm"; $pm->import( '$data' );
It's a bit harder to read, but you might put that into a subroutine called my_use() and call it that way. (There's a CPAN module that does this for you, but I don't remember its name off the bat.)

* Well, not exactly, but the exact details would only get in the way.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

In reply to Re^3: modules as data files by dragonchild
in thread modules as data files by Anonymous Monk

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.