in reply to Circular use doesn't call import() as expected...?
Here is how that rule plays out in this case.
This will change the output to:package a; sub import { print "import #1 in $_[0] called from ". (caller(1))[3] ." \n"; } use b; sub import { print "import #2 in $_[0] called from ". (caller(1))[3] ." \n"; }
and you can see that b.pm really is calling a->import, but Perl has only compiled the file up to the use statement.import #1 in a called from b::BEGIN import in b called from a::BEGIN import #2 in a called from main::BEGIN
(General note. Circular dependencies tend to be poorly handled in many languages. If you can, you really want to avoid that. One strategy to handle the circularity is to explicitly require and import in the module that you want to see be loaded first. Another is to move critical code - such as imports - so they are executed before use statements.)
|
|---|