in reply to Re^3: Making it clearer to say that a sub is defined within current package
in thread Making it clearer to say that a sub is defined within current package

In a clean design you don't want My:: to have effect outside the scope using it.

Also probably a lowercase name my:: for pragma would be more appropriate to avoid a clash with cpan modules.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^4: Making it clearer to say that a sub is defined within current package

Replies are listed 'Best First'.
Re^5: Making it clearer to say that a sub is defined within current package
by Eily (Monsignor) on Apr 11, 2019 at 15:54 UTC

    Checking caller and dying when the function does not exist in the caller package wouldn't be much different than dying when calling an undefined function with the package prefix.

    The main problem is that calling local functions as my::something() makes strict's job harder.

      I was talking about the need to have a hinthash to restrict the effects of "use My" to the scope.

      What are you talking about?

      I don't want to collide with any other product which is using My:: for its own purpose. Of course does the caller change.

      But any magic should be restricted to the local scope!

      Anyway reserving the Namespace on CPAN would be needed.

      update

      another idea would be using a lexical object, and the method call would be channeled through AUTOLOAD.

      my $mysubs = new Mysubs; $mysubs->xyz();

      this could indeed work without polluting other packages and the runtime effects would become obvious by the ->arrow .

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Ah, right. I understood that you were saying that calling My::function from a module that does not define function would yield unexpected results. The actual message makes more sense :D.

        If there are already package that use My:: without having reserved the keyword, they already are risky on their own anyway, if you ever end up including more than one of those in one program.