Re: Exporter and subroutine circular dependencies between modules
[email protected] (Diab Jerius) Sun, 13 Mar 2022 19:42:00 -0400
| Newsgroups | perl.module-authors |
|---|---|
| Message-ID | <[email protected]> |
--------------SXOOkL05bMQUYR0t98p1oR1w
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
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.
--------------SXOOkL05bMQUYR0t98p1oR1w
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 3/13/22 19:12, Shawn H Corey wrote:<br>
</div>
<blockquote type="cite"
cite="mid:[email protected]">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<div class="moz-cite-prefix">On 2022-03-13 18:44, Diab Jerius
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CADpyd5CGZYt=O0fNCg9xL3ph687F3BD+u7LUQztqDVNwnC61mA@mail.gmail.com">
<div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<p><br>
</p>
</div>
</blockquote>
</div>
</div>
<div dir="auto">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).</div>
</blockquote>
<p>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.<br>
</p>
</blockquote>
<p> Except that in this case, the two modules are importing each
other, so that this linear model does not hold.</p>
<p>I'm back at my keyboard, so can implement your suggestion.</p>
<blockquote>
<p>$ diff Exporter-circular-use{.orig,.new}<br>
diff Exporter-circular-use.orig/Bar11.pm
Exporter-circular-use.new/Bar11.pm<br>
9,10c9<br>
< require Exporter;<br>
< our @ISA = qw( Exporter );<br>
---<br>
> use Exporter 'import';<br>
diff Exporter-circular-use.orig/Foo11.pm
Exporter-circular-use.new/Foo11.pm<br>
9,10c9<br>
< require Exporter;<br>
< our @ISA = qw( Exporter );<br>
---<br>
> use Exporter 'import';<br>
</p>
</blockquote>
<p>With the same unfortunate result:<br>
</p>
<blockquote>
<p>$ perl foo11<br>
main=7<br>
foo=6<br>
bar=5<br>
Undefined subroutine &Bar11::foo called at Bar11.pm line 21.<br>
</p>
</blockquote>
<p><br>
</p>
</body>
</html>
--------------SXOOkL05bMQUYR0t98p1oR1w--