in reply to Re: Creating "parasitic" exports
in thread Creating "parasitic" exports

Thanks for the suggestion =)

That's what I tried first, but then I realized that every time the export list changes in Foo::Core, it has to be updated in Foo::Core::Specialized. That's a less elegant solution than re-implementing Exporter's import within my own, so I opted against it.

Replies are listed 'Best First'.
Re^3: Creating "parasitic" exports
by BrowserUk (Patriarch) on Nov 18, 2009 at 17:41 UTC
    every time the export list changes in Foo::Core, it has to be updated in Foo::Core::Specialized.

    Why? Why not just initialise F::C::S's EXPORT* vars from F::C's?

    package Foo::Core::Specialised; use Foo::Core ':all'; our @EXPORT = @Foo::Core:@EXPORT; our @EXPORT_OK = @Foo::Core::EXPORT_OK; our %EXPORT_TAGS = %Foo::Core::EXPORT_TAGS; ## Add, subtract or overwrite as required.

    That way F::C::S can export everything F::C can unless you explicitly remove it--self maintaining--plus anything you add or overwrite.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Why? Why not just initialise F::C::S's EXPORT* vars from F::C's?

      package Foo::Core::Specialised; use Foo::Core ':all'; our @EXPORT = @Foo::Core:@EXPORT; our @EXPORT_OK = @Foo::Core::EXPORT_OK; our %EXPORT_TAGS = %Foo::Core::EXPORT_TAGS; <b>## Add, subtract or overwrite as required.</b>

      Well, maybe this is the part I don't get. How can I modify the @import list without overwriting the import() function? If I have to overwrite the import() method to be able to modify the args, then the same question applies -- how do I export from F::C?

        Given a::b.pm:

        package a::b; require Exporter; our @ISA = qw[ Exporter ]; our @EXPORT = qw[ foo ]; our @EXPORT_OK = qw[ foo bar qux ]; our %EXPORT_TAGS = ( all => [ @EXPORT_OK ], ); sub foo{ print 'fooey|' } sub bar{ print 'Baaa!' } sub qux{ print 'Qux?!' } 1;

        And a::b::c.pm:

        package a::b::c; use a::b qw[ :all ]; require Exporter; our @ISA = qw[ Exporter ]; our @EXPORT = @a::b::EXPORT; our @EXPORT_OK = ( @a::b::EXPORT_OK, 'sensible' ); our %EXPORT_TAGS = %a::b::EXPORT_TAGS; push @{ $EXPORT_TAGS{ all } }, 'sensible'; sub sensible{ print 'sensible' } 1;

        Then importer.pl:

        #! perl -slw use a::b::c qw[ :all ]; foo(); bar(); qux(); sensible();

        Produces this:

        c:\test>importer fooey| Baaa! Qux?! sensible

        Anything added to a::b.pm will automatically be available for import through a::b::c.pm without modifications.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.