Stupid Import Idea? (from.pm)

Ovid on 2008-04-17T12:51:05

Sometimes you use a module and you don't want everything it exports. Or perhaps it exports nothing.

use from 'Some::Module' => qw/func1 func2/;
# or
use from 'Some::Module' =>
  func1 => { as => 'munge' },  # alias to avoid conflicts
  'func2';

As a concrete example (this allows me to reimplement the other functions it exports by default):

use from 'Test::Exception' => 'throws_ok';

Stupid?


not stupid

markjugg on 2008-04-17T13:59:38

This is a reasonable thing to want to do. What may feel hackish about is that it is not an automatic feature, like Sub::Exporter provides.

But when the module you want to "use" isn't under your control, you have to workaround it somehow. Sub::Exporter does provide a recipe to do this for modules that use Exporter.pm:

http://search.cpan.org/user/rjbs/Sub-Exporter-0.978/lib/Sub/Exporter/Cookbook.pod#Ea ting_Exporter.pm's_Brain

      Mark