in reply to Re^2: Multiple Packages in a Module? (%INC)
in thread Multiple Packages in a Module?
A use is a require + import and the require part is skipped after checking %INC
(Of course you need to place Foo::Bar before Foo if the latter uses the former.)
But if you have a special example in mind where this breaks, please share.
> if a use Foo::Bar ; is executed after the usurping module test_v1.pm has been loaded
as demonstrated you can use Foo::Bar as soon as the BEGIN block sets %INC.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) well if the module is written in a way that BEGIN blocks expect to be run after the use (i.e. in the inherent do FILE), then yes could get bitten by order problems. The OP didn't sound like his intention was to simulate meta programming magics.
Otherwise he should do a BEGIN { eval $MODULE_CODE; package->import() }
Please note that this code could be encapsulated in a special module.
Something like use FromData "__MODULE_NAME__" could extract the Modules_Code from the DATA section (delimited by __MODULE_NAME__ ) and import it into the upper namespace.
Another - probably more elegant - option is to provide a loader function as value in %INC . use would evaluate this function to get the MODULE_CODE.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Multiple Packages in a Module? (%INC)
by AnomalousMonk (Archbishop) on Jun 25, 2018 at 22:13 UTC | |
by LanX (Saint) on Jun 25, 2018 at 22:29 UTC | |
Re^4: Multiple Packages in a Module? (%INC)
by haj (Vicar) on Jun 25, 2018 at 23:08 UTC |