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

In general, you're right. But...

It is possible to make subroutines un-callable from a scope, it just makes the code uglier :-)

package Whatever; { # anything outside this scope can't call this: my $private1 = sub { print "hello"; }; # everybody can call Whatever::foo sub foo { $private1->(); # call private method print " world\n"; } } foo();

Replies are listed 'Best First'.
Re^5: Using Exporter module
by ikegami (Patriarch) on Jul 19, 2007 at 14:32 UTC

    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).