Continuing on from my earlier question, "use"ing from dynamic namespace, I've found myself needlessly repeating things like
use Base::Module; Base::Module::Config->import(qw( %conf ));
every time I used this code. So, naturally, I thought, I'd just re-export those from the core:
package Base::Module; use strict; use warnings; sub config_module { "Base::Module::Config" } use base 'Exporter'; BEGIN { our @EXPORT_OK = qw( &%conf ); eval 'require ' . config_module; no strict 'refs'; no warnings 'once'; *conf = \%{config_module . '::conf'}; }
This comes deceptively close to working, but I'm seeing some users of Base::Module getting one %conf and others getting a different %conf. I suspect that it's related to whether they import it using
use Base::Module qw( %conf );
or
sub base_module { "Base::Module" } BEGIN { eval 'require ' . base_module; base_module()->import(qw( %conf )); }
but I'm not positive. It could also be the distinction between being used in the final program (first form) vs. being used by other modules which are a part of this structure (second form).

In any case, what would be the correct (or at least a fully-working) way to accomplish this?


In reply to Re-exporting dynamically-included variables by dsheroh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.