in reply to Re: One module to use them all (proxy moudle that exports subs of other modules)
in thread One module to use them all (proxy moudle that exports subs of other modules)

Oups... Sorry... not that easy... Some of MyMod* modules (that are not really mine) does not use Exporter. And this breaks everything :-(

  • Comment on Re^2: One module to use them all (proxy moudle that exports subs of other modules)

Replies are listed 'Best First'.
Re^3: One module to use them all (proxy moudle that exports subs of other modules) (updated)
by AnomalousMonk (Archbishop) on Sep 03, 2022 at 00:15 UTC

    Based on choroba's ++reply, here's a (partial?) solution (?) that may be closer to what you want.

    tldr.pl:

    # from choroba pm#11146644 (modified) use warnings; use strict; use ModAll; print "'$_' \n" for Foo::bar(qw(some stuff)), m1(), m2('whatever'), m3 +;
    ModAll.pm:
    # from choroba pm#11146644 (modified) package ModAll; use warnings; use strict; # use Data::Dump qw(dd); # for debug use constant USE_ALL => qw(Mod1 Mod2 Mod3 Foo); eval "use $_" for USE_ALL; use Exporter 'import'; our @EXPORT = map eval, map "\@${_}::EXPORT", USE_ALL ; __PACKAGE__
    Mod1.pm:
    package Mod1; use warnings; use strict; use Exporter 'import'; our @EXPORT = qw( m1 ); sub m1 { "m1(@_)" } __PACKAGE__
    Mod2.pm:
    package Mod2; use warnings; use strict; use Exporter 'import'; our @EXPORT = qw( m2 ); sub m2 { "m2(@_)" } __PACKAGE__
    Mod3.pm:
    package Mod3; use warnings; use strict; use Exporter 'import'; our @EXPORT = qw( m3 ); sub m3 { "m3(@_)" } __PACKAGE__
    Foo.pm (forgot this previously):
    # Foo.pm package Foo; use strict; use warnings; sub bar { sprintf "hiya from -%s-(@_) invoked from '%s'", (caller 0)[3, 0]; } 1;
    Invocation:
    Win8 Strawberry 5.8.9.5 (32) Fri 09/02/2022 19:51:48 C:\@Work\Perl\monks\nataraj >perl tldr.pl 'hiya from -Foo::bar-(some stuff) invoked from 'main'' 'm1()' 'm2(whatever)' 'm3()'
    (Caution: There may be some important phasing considerations in my version of ModAll.pm that I'm overlooking!)

    Update: Forgot to list the Foo.pm module. It's listed elsewhere, but I've added it here for completeness.


    Give a man a fish:  <%-{-{-{-<

Re^3: One module to use them all (proxy moudle that exports subs of other modules)
by AnomalousMonk (Archbishop) on Sep 02, 2022 at 22:36 UTC
    Some of MyMod* modules ... does not use Exporter.

    So what do they use?

    Is it possible that some of the modules do not export at all, i.e., the fully-qualified name of a subroutine or package-global variable defined in the module must be used to invoke the subroutine/variable? E.g.:
    File Foo.pm:

    # Foo.pm package Foo; use strict; use warnings; sub bar { printf "hiya from -%s-(@_) invoked from '%s' \n", (caller 0)[3, 0] +; } 1;
    Invocation:
    Win8 Strawberry 5.8.9.5 (32) Fri 09/02/2022 18:25:19 C:\@Work\Perl\monks\nataraj >perl -wMstrict -le "use Foo; Foo::bar(qw(some stuff)); print 'ok'" hiya from -Foo::bar-(some stuff) invoked from 'main' ok
    This situation can be addressed, but we need these details.


    Give a man a fish:  <%-{-{-{-<

Re^3: One module to use them all (proxy moudle that exports subs of other modules)
by syphilis (Archbishop) on Sep 03, 2022 at 05:56 UTC
    And this breaks everything :-(

    I don't see how the absence of Exporter in any of those modules would cause breakage.
    Can you provide more details ?

    Cheers,
    Rob
      I don't see how the absence of Exporter in any of those modules would cause breakage. Can you provide more details ?

      Because the solutions that assume Exporter specifically assume the existance of @EXPORT in every one of the sub-modules. My Two.pm does not contain @EXPORT, and thus none of Two.pm's functions would be exported to the tldr script if my ::All had our @EXPORT = (@Mod11146642::One::EXPORT, @Mod11146642::Two::EXPORT); instead of the our @EXPORT = @inherited; and the stash-diff that populated @inherited. If I used the EXPORT-assuming line, ignoring @inherited, I would get

      C:\usr\local\share\PassThru\perl\perlmonks > 11146642-tldr.pl Called Mod11146642::One::oneFunction() Undefined subroutine &main::twoFunction called at C:\usr\local\share\P +assThru\perl\perlmonks\11146642-tldr.pl line 14.