in reply to importing/removing functions from a module into the main namespace

If the arguments to use after the module name are function names, they will be imported. use MyBot qw/afunc another thethird/; The Exporter module can be used as a base class in MyBot.pm to get tagged exports and other goodies.

After Compline,
Zaxo

  • Comment on Re: importing/removing functions from a module into the main namespace
  • Download Code

Replies are listed 'Best First'.
Re^2: importing/removing functions from a module into the main namespace
by agaffney (Beadle) on Mar 14, 2005 at 08:09 UTC
    What about reloading the module? Do I just 'use MyModule qw/foo bar baz/;' again?
      use and require normally only load a module once during execution of the script, even if they're called multiple times. Any imports done by use will be done for each use statement, though.

      If you really want to reload a module while running the program, you can do something like this (not 100% foolproof):

      use Symbol qw(delete_package); sub re_use { my $module = shift; # "Module::To::Reload" my $fname = $module; $fname =~ s#::#/#g; $fname .= ".pm"; # "Module/To/Reload.pm" delete_package($module); # remove the Module::To::Reload namespace delete $INC{$fname}; # delete the filename from the # "loaded" list eval "use $module" or die $@; }
        Actually, I just had someone point me to the Module::Reload module which seems to do exactly what I need. Thanks, though.