in reply to Behaviour on recursive use

It's not a problem from perl's perspective, but behaviour in the case of circular requires can sometimes be a little unintuitive:

# foo.pm package foo; use bar; sub import { printf("%s loaded foo\n", scalar caller) } 1;
# bar.pm package bar; use foo; sub import { printf("%s loaded bar\n", scalar caller) } 1;
# script.pl use foo;

Running the script, generates the following output:

foo loaded bar main loaded foo

Did you expect to see bar loaded foo somewhere in that output?

With careful consideration of compile time versus runtime, etc, etc, you'll realise why that line was not output, and that this is proper and documented behaviour. Just not necessarily very intuitive.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: Behaviour on recursive use
by locinus33 (Initiate) on Mar 10, 2014 at 10:32 UTC

    Fair enough. Thank you for leading me in the way.

    So, according to the imports order, the compiler will or won't load the different variables/subs in the right order, so that in my example, we have :

    ========= OK test : load A1 -> load A2 -> load C (but constant TYPE is not loaded already) -> not load A2 (already 'used') -> load constant TYPE ========= KO test : load A1 -> load C (but constant TYPE is not loaded already) -> load A2 -> not load C (already 'used') -> fail because constant TYPE is not loaded

    Is that right?

    Ok. What about the "C->TYPE" vs "C::TYPE", the first being the one that always works whatever the 'use' order. Is that a "runtime" vs "compile time", as you pointed out?

    Cheers.

        Well, thanks for those explanations! it makes it all clearer about Perl's interpretation.

        Yeah, I know for the circular dependencies, I have to work on it.

        Thanks !