Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: How to call a perl function without its context?

by kitomer (Novice)
on Jul 28, 2015 at 11:42 UTC ( [id://1136590]=note: print w/replies, xml ) Need Help??


in reply to Re: How to call a perl function without its context?
in thread How to call a perl function without its context?

Yes for security reasons I want to make sure a function does not access anything beyond its "lexical variables declared within the function scope" (Thank you BrowserUk). Basicly I want to write pure functions that will throw a compile-time error when they are not pure.
  • Comment on Re^2: How to call a perl function without its context?

Replies are listed 'Best First'.
Re^3: How to call a perl function without its context?
by Monk::Thomas (Friar) on Jul 28, 2015 at 12:38 UTC

    Basicly I want to write pure functions that will throw a compile-time error when they are not pure.

    Your definition of 'pure' is different from my definition of 'pure'.

    A 'pure' (as in functional programming) function ~can~ use external variables and still be called pure. It must not modify these variables, but it would be perfectly fine to have a sin(x) where you provide π as an external value. Changing π will change the actual output value, but if you repeat the calculation it will a) result in the same output value and b) x and π will not be modified.

Re^3: How to call a perl function without its context?
by Corion (Patriarch) on Jul 28, 2015 at 12:05 UTC

    If you want to reject functions that access global state, consider what B::Xref provides you. With that, you can get at a list of global variables used by a function.

Re^3: How to call a perl function without its context?
by BrowserUk (Patriarch) on Jul 28, 2015 at 12:07 UTC
Re^3: How to call a perl function without its context?
by marinersk (Priest) on Jul 30, 2015 at 16:53 UTC

    I'll need to check out Safeand its family, as they may have addressed the problem.

    My current thought would be to develop each function (presuming this is synonymous with a Perl subroutine in this context) initially as a stand-alone file, with use strict;and use warnings;at the top and a calling routine built in.

    If it compiles without errors, there are no external references.

    Then a quick process to extract only the subroutine into your main code and you're off to the races.

    The weakness is that if one bypasses the build procedure, one can violate the constraint.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1136590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found