Groups | Search | Server Info | Login | Register
Groups > perl.module-authors > #3390
| Newsgroups | perl.module-authors |
|---|---|
| Message-ID | <bb7d6bac-4e2b-602e-55f3-e453989fab17@holgerdanske.com> (permalink) |
| Date | 2022-03-13 19:13 -0700 |
| Subject | Re: Exporter and subroutine circular dependencies between modules |
| References | <c4a1dd1b-bfa5-2991-271b-360a6bb1ea0a@holgerdanske.com> <a67a9dde-a2af-3842-1590-635a9509f7e9@cfa.harvard.edu> <8e3ac525-d759-365c-8e26-3f395a784308@gmail.com> |
| From | dpchrist@holgerdanske.com (David Christensen) |
[Multipart message — attachments visible in raw view] - view raw
On 3/13/22 15:18, Shawn H Corey wrote:
> On 2022-03-13 18:08, Diab Jerius via module-authors wrote:
>>
>> require Exporter;
>> our @ISA = qw( Exporter );
>> our @EXPORT = qw( foo )
>>
> I prefer this way:
>
> # --------------------------------------
> # Exports
> use Exporter qw( import );
> our @EXPORT = qw( foo );
> our @EXPORT_OK = qw( );
> our %EXPORT_TAGS = (
> all => [ @EXPORT, @EXPORT_OK ],
> );
>
> This automatically creates a tag for `:all`.
Thank you for the reply. :-)
That approach does not solve the circular dependency issue:
2022-03-13 19:02:58 dpchrist@tinkywinky
~/samba/dpchrist/sandbox/perl/Exporter-circular-use
$ cat /etc/debian_version ; uname -a ; perl -v | head -n 2
9.13
Linux tinkywinky 4.9.0-17-amd64 #1 SMP Debian 4.9.290-1 (2021-12-12)
x86_64 GNU/Linux
This is perl 5, version 24, subversion 1 (v5.24.1) built for
x86_64-linux-gnu-thread-multi
2022-03-13 19:03:22 dpchrist@tinkywinky
~/samba/dpchrist/sandbox/perl/Exporter-circular-use
$ cvs diff
Index: Bar11.pm
===================================================================
RCS file:
/var/local/cvs/dpchrist/sandbox/perl/Exporter-circular-use/Bar11.pm,v
retrieving revision 1.1
diff -r1.1 Bar11.pm
9,11c9,14
< require Exporter;
< our @ISA = qw( Exporter );
< our @EXPORT = qw( bar );
---
> use Exporter qw( import );
> our @EXPORT = qw( bar );
> our @EXPORT_OK = qw();
> our %EXPORT_TAGS = (
> all => [ @EXPORT, @EXPORT_OK ],
> );
Index: Foo11.pm
===================================================================
RCS file:
/var/local/cvs/dpchrist/sandbox/perl/Exporter-circular-use/Foo11.pm,v
retrieving revision 1.1
diff -r1.1 Foo11.pm
9,11c9,15
< require Exporter;
< our @ISA = qw( Exporter );
< our @EXPORT = qw( foo );
---
> use Exporter qw( import );
> our @EXPORT = qw( foo );
> our @EXPORT_OK = qw();
> our %EXPORT_TAGS = (
> all => [ @EXPORT, @EXPORT_OK ],
> );
>
2022-03-13 19:03:24 dpchrist@tinkywinky
~/samba/dpchrist/sandbox/perl/Exporter-circular-use
$ ./foo11
main=7
foo=6
bar=5
Undefined subroutine &Bar11::foo called at Bar11.pm line 25.
And, I have doubts about use'ing Exporter and importing Exporter::import().
But, you have reminded me that it is better style to export nothing by
default (the demo script and modules used @EXPORT for brevity).
So, combining the ideas thus far:
BEGIN { our @EXPORT_OK = qw( foo ) }
use parent 'Exporter';
David
2022-03-13 19:06:46 dpchrist@tinkywinky
~/samba/dpchrist/sandbox/perl/Exporter-circular-use
$ ./Exporter-circular-use.t
ok 1 - foo00
ok 2 - foo01
ok 3 - foo10
Undefined subroutine &Bar11::foo called at Bar11.pm line 22.
not ok 4 - foo11
# Failed test 'foo11'
# at ./Exporter-circular-use.t line 24.
# got: 'main=7
# foo=6
# bar=5
# '
# expected: 'main=7
# foo=6
# bar=5
# foo=4
# bar=3
# foo=2
# bar=1
# '
Undefined subroutine &Bar12::foo called at Bar12.pm line 23.
not ok 5 - foo12
# Failed test 'foo12'
# at ./Exporter-circular-use.t line 24.
# got: 'main=7
# foo=6
# bar=5
# '
# expected: 'main=7
# foo=6
# bar=5
# foo=4
# bar=3
# foo=2
# bar=1
# '
ok 6 - foo21
ok 7 - foo22
ok 8 - foo33
ok 9 - foo44
1..9
# Looks like you failed 2 tests of 9.
Back to perl.module-authors | Previous | Next — Previous in thread | Next in thread | Find similar
Exporter and subroutine circular dependencies between modules dpchrist@holgerdanske.com (David Christensen) - 2022-03-13 13:13 -0700
Re: Exporter and subroutine circular dependencies between modules dpchrist@holgerdanske.com (David Christensen) - 2022-03-13 18:43 -0700
Re: Exporter and subroutine circular dependencies between modules dpchrist@holgerdanske.com (David Christensen) - 2022-03-13 19:13 -0700
Re: Exporter and subroutine circular dependencies between modules dpchrist@holgerdanske.com (David Christensen) - 2022-03-13 19:29 -0700
Re: Exporter and subroutine circular dependencies between modules dpchrist@holgerdanske.com (David Christensen) - 2022-06-05 19:05 -0700
csiph-web