develooper Front page | perl.module-authors | Postings from March 2022

Re: Exporter and subroutine circular dependencies between modules

Thread Previous | Thread Next
From:
Diab Jerius
Date:
March 13, 2022 23:42
Subject:
Re: Exporter and subroutine circular dependencies between modules
Message ID:
af75f6e4-e60f-d54e-568f-553d5e7a1c68@cpan.org

On 3/13/22 19:12, Shawn H Corey wrote:
> On 2022-03-13 18:44, Diab Jerius wrote:
>>
>>
>> I prefer yet another fashion (everything is driven by what's in 
>> %EXPORT_TAGS), but back to the point of the OP's problem, this 
>> doesn't initialize @EXPORT until runtime, so I think will have the 
>> same issue (I'm away from keyboard at the moment).
>
> Each module has its own runtime. That is, a module is loaded, compiled 
> and run; all before the main program. In other words, when the module 
> returns from its `use` statement, it has already run.
>
Except that in this case, the two modules are importing each other, so 
that this linear model does not hold.

I'm back at my keyboard, so can implement your suggestion.

    $ diff Exporter-circular-use{.orig,.new}
    diff Exporter-circular-use.orig/Bar11.pm
    Exporter-circular-use.new/Bar11.pm
    9,10c9
    < require Exporter;
    < our @ISA    = qw( Exporter );
    ---
     > use Exporter 'import';
    diff Exporter-circular-use.orig/Foo11.pm
    Exporter-circular-use.new/Foo11.pm
    9,10c9
    < require Exporter;
    < our @ISA    = qw( Exporter );
    ---
     > use Exporter 'import';

With the same unfortunate result:

    $ perl foo11
    main=7
      foo=6
       bar=5
    Undefined subroutine &Bar11::foo called at Bar11.pm line 21.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About