Re: Exporter and subroutine circular dependencies between modules

[email protected] (David Christensen) Sun, 13 Mar 2022 19:13:44 -0700
Newsgroups perl.module-authors
Message-ID <[email protected]>
--------------QhLs0K6PEYjWknw1iqBHJ4fY
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

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.
--------------QhLs0K6PEYjWknw1iqBHJ4fY
Content-Type: application/gzip;
 name="Exporter-circular-use-20220313-185149.tar.gz"
Content-Disposition: attachment;
 filename="Exporter-circular-use-20220313-185149.tar.gz"
Content-Transfer-Encoding: base64

H4sIAAegLmI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