in reply to Re: Using Exporter module
in thread Using Exporter module

Thanks for reply.
What is the way to stop exporting all functions in calling program ? is there any way or I am just trying to do things that is not possible.

Replies are listed 'Best First'.
Re^3: Using Exporter module
by ikegami (Patriarch) on Jul 18, 2007 at 20:04 UTC

    Exporting doesn't mean what you think it does, at least not in Perl. To export is to remove the requirement to use a fully qualified name.

    What you really want, it seems, is to make a function uncallable from outside of {something}. (A namespace? Code that originated from a certain file?) Perl doesn't provide any direct means of doing that. Perl considers this a documentation issue. If a user of your module disreguards your documentation and call a function he shouldn't, it's his own foot he's shooting.

    Many programmers prepend an underscore (_) to the name of their private subs/methods as an indication that they shouldn't be called.

        Another way would be to check caller.

        I didn't say it was impossible, just that Perl didn't support it. Your way requires rewritting all the calls to the function. Using caller requires knowing the name of all the functions that will call each private function. That's ugly, fragile and best avoided. In fact, I judged best not even mentioning them.

        By the way, both ways can be circumvented (with difficulty).

      I think we can acheive this by creating private method. and not call like $self->_method() Inside module
      if we call the private method like this: _method($self,arguments.) and if we try to call this subroutine outside then this will thorw an error.