in reply to Re^2: 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

Well that's an issue if you want to set *My::Dumper = *Data::Dumper::Dumper once and for all. But if the only function defined in my is My::AUTOLOAD, and it always checks the calling package you should be fine wouldn't you? (At execution time at least, you'd lose compilation time errors with My::function() instead of function())

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

Replies are listed 'Best First'.
Re^4: Making it clearer to say that a sub is defined within current package
by LanX (Saint) on Apr 11, 2019 at 15:45 UTC
    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

      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