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.
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! :)
added dump of \%INC for illustration
˛) 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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |