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.

Attachment: Exporter-circular-use-20220313-185149.tar.gz
Description: application/gzip

Reply via email to