Re: Exporter and subroutine circular dependencies between modules
[email protected] (Karen Etheridge) Sun, 13 Mar 2022 14:57:48 -0700
| Newsgroups | perl.module-authors |
|---|---|
| Message-ID | <CAPJsHfC=mfMDgsgCsZb6NXAv4bbzuSomFvt3LQyfyunCuvowyw@mail.gmail.com> |
--00000000000088e6ae05da20a8d0
Content-Type: text/plain; charset="UTF-8"
I haven't looked at your code, but I assume what you're doing is exporting
a sub from each module, and something in each of those modules is calling
each of those subs in turn, using the exported symbol. This is indeed an
unresolvable circular dependency because unqualified sub names must be
resolved at compile (i.e. "use" or BEGIN{}) time.
One solution is to not import all the symbols -- break the cycle by simply
'use'ing a module without importing its subs, and call that sub by its
fully-qualified name (e.g. Foo::foo() rather than foo()), which only needs
to be resolvable at runtime.
On Sun, Mar 13, 2022 at 1:14 PM David Christensen <[email protected]>
wrote:
> module-authors:
>
> I have been wrestling with the Exporter module and subroutine circular
> dependencies between modules for a number of years. I have yet to find
>
--00000000000088e6ae05da20a8d0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div>I haven't looked at your code, b=
ut I assume what you're doing is exporting a sub from each module, and =
something in each of those modules is calling each of those subs in turn, u=
sing the exported symbol. This is indeed an unresolvable circular dependenc=
y because unqualified sub names must be resolved at compile (i.e. "use=
" or BEGIN{}) time.</div><div><br></div><div>One solution is to not im=
port all the symbols -- break the cycle by simply 'use'ing a module=
without importing its subs, and call that sub by its fully-qualified name =
(e.g. Foo::foo() rather than foo()), which only needs to be resolvable at r=
untime.</div><div><br></div><div><br></div></div><div class=3D"gmail_quote"=
><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Mar 13, 2022 at 1:14 PM Davi=
d Christensen <<a href=3D"mailto:[email protected]">dpchrist@hol=
gerdanske.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi=
ng-left:1ex">module-authors:<br>
<br>
I have been wrestling with the Exporter module and subroutine circular <br>
dependencies between modules for a number of years.=C2=A0 I have yet to fin=
d <br></blockquote></div></div>
--00000000000088e6ae05da20a8d0--