Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The OP has existing modules which do not have an import function because they do not have use EXPORTER;. Would it not be easier to add that line than a custom import function? Adding *twoFunction =\&Mod11146642::All::twoFunction; to the new module Mod11146642::All should do the same thing for this application and not affect anything else.

Long UPDATE to Clarify my point

Nataraj has posted the following update to One module to use them all (proxy moudle that exports subs of other modules).
Update: Partially solved here. This solution (Re: One module to use them all (proxy moudle that exports subs of other modules)) works for modules that uses Export for exporting. For other modules I added desired subs to export list explicitly. This did most of the trick.
From this I assume that most functions ‘work’ (i.e. The application tldr.pl can access them with unqualified names) . Later, he tells us that all the exceptions are in third party (‘not really mine’) modules which do not have use EXPORTER. It is reasonable to assume that these modules do not have an appropriate ‘import’ function. At least three solutions have been proposed. Any one of them would ‘work’ . None of them are exactly what the OP was hoping for.
  • Manually ‘import’ the function name(s) into the proxy module.
  • Edit the module to add use EXPORT
  • Edit the module to add a custom import function.

The second and third option are probably not available for third party modules. The first option has the advantage that all extra code is added to the ‘proxy’ module ‘ModAll’. This method fails to meet the OP's expectations only because the proxy module must be manually updated every time the library of third party functions is reorganized.

Demo of ‘manual’ method

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

The following files are unchanged

  • tldr.pl
  • Mod1.pm
  • Mod2.pm

EXPORTER has been removed from Mod3.pm to simulate a 'third party' module.

package Mod3; use warnings; use strict; #use Exporter 'import'; #our @EXPORT = qw( m3 ); sub m3 { 'm3' } __PACKAGE__

Manual ‘import’ added to ModAll.pm

package ModAll; use warnings; use strict; use Mod1; use Mod2; use Mod3; use Exporter 'import'; # Supply function name ‘m3’ manually (not in any EXPORT list) #our @EXPORT = (@Mod1::EXPORT, @Mod2::EXPORT, @Mod3::EXPORT); our @EXPORT = (@Mod1::EXPORT, @Mod2::EXPORT, ‘m3’); *m3 = \&Mod3::m3 # hand code result of missing import; __PACKAGE__
Bill

In reply to Re^2: One module to use them all (proxy moudle that exports subs of other modules) by BillKSmith
in thread One module to use them all (proxy moudle that exports subs of other modules) by nataraj

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-24 10:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found