in reply to Call subroutine of main namespace from package in Plack

Why do you need it? Calling functions from the main:: namespace in modules is a code smell. And now we also see why. How do you run the script under plackup?

Also, please, linkify the crosspost link by at least wrapping it into square brackets.

Update: I tried to just run

plackup program.pl
(and I added
1;
to the end of Mypackage.pm.

To debug, you can add

warn __PACKAGE__;
inside the BEGIN block before defining the test subroutine. You'll see that plack doesn't call your program in the main namespace.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Call subroutine of main namespace from package in Plack
by Thenothing (Sexton) on Apr 11, 2018 at 14:51 UTC

    Hi choroba, I have a main script app.psgi, inside I have several modules, modules in my local folder like module1.pm, module2.pm, etc

    This modules have own functions.

    In the app.psgi I have anothers functions relation to router engine urls, to dispach content according to url.

    My target is set a value or get a value from main script (app.psgi) and pass that value to all modules, and retrieve the value from module via the function set in main script.

    * To do this I can pass a function value to another function.
    * I can create a our variable
    * I can used db to retrieve data

    But I want to avoid the above list, that's why the title of this thread.

      I don't understand. A module doesn't know who calls it, it can't make any assumptions about its caller's namespace and capabilities. The contract is defined by arguments and the returned value. If you need a function called in the main program and in the modules, move it into a new module and properly use it everywhere.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,