Call Function in .pm as another user

Hello,

I need to call a function which reside in some package moudle (.pm)
as another user by using su -.
Are anyone know how can I do it?

Thanks

I don't think it can be done out of the box, once the script is started, there's a PID assigned, along with user parameters - uid and gid. Then, if you need a subroutine called, whose code requires root privileges, I don't think you can change it.
Possible solution : use perl's module expect, write a section that executes some code, and when it comes to the root, start another shell, save the subroutine in a different file, spawn "su -", provide password, and execute this script, then return back to the original one. This has drawback - you have to leave your root password in a script.
Personally I'm not aware of a method for changing the UID dynamically, but I'll be glad to hear solution too.