> I want to have a set of files test_v1.pm .. test_vN.pm that each have definitions of package Foo and package Foo::Bar

After useing test_v*.pm you have to make Perl believe that package Foo and package Foo::Bar have already been loaded ...

i.e. you have to flag it in %INC: °

The hash %INC contains entries for each filename included via the do, require, or use operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found. The require operator uses this hash to determine whether a particular file has already been included.

I had a similar discussion some time ago, I'll dig it up and update it here.

EDIT

Couldn't find it, here a little demo:

use strict; use warnings; use Data::Dump qw/pp dd/; package Foo::Bar; sub import { warn __PACKAGE__." was imported!" } BEGIN { $INC{'Foo/Bar.pm'}=1; # actually a path needed, but 1 is true eno +ugh˛ ;-) } package main; use Foo::Bar; warn pp \%INC;
Foo::Bar was imported! at d:/Users/lanx/pm/inc.pl line 10. { "C:/Perl_64/site/lib/sitecustomize.pl" => "C:/Perl_64/site/lib/sitec +ustomize.pl", "Data/Dump.pm" => "C:/Perl_64/lib/Data/Dump. +pm", "Exporter.pm" => "C:/Perl_64/lib/Exporter.p +m", "Foo/Bar.pm" => 1, "overload.pm" => "C:/Perl_64/lib/overload.p +m", "overloading.pm" => "C:/Perl_64/lib/overloadin +g.pm", "strict.pm" => "C:/Perl_64/lib/strict.pm" +, "subs.pm" => "C:/Perl_64/lib/subs.pm", "vars.pm" => "C:/Perl_64/lib/vars.pm", "warnings.pm" => "C:/Perl_64/lib/warnings.p +m", "warnings/register.pm" => "C:/Perl_64/lib/warnings/r +egister.pm", } at d:/Users/lanx/pm/inc.pl line 21.

HTH! :)

update

added dump of \%INC for illustration

update

˛) using __FILE__ instead of 1 is even better, because the origin of the code will become obvious when debugging.

BEGIN { $INC{'Foo/Bar.pm'}=__FILE__; }

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) %INC the hash not @INC the array!


In reply to Re: Multiple Packages in a Module? (manipulate %INC) by LanX
in thread Multiple Packages in a Module? 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.