Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Loading PERL Module from scalar in RAM? (@INC hook)

by LanX (Saint)
on Apr 16, 2023 at 19:32 UTC ( [id://11151705]=note: print w/replies, xml ) Need Help??


in reply to Loading PERL Module from scalar in RAM?

@INC has a hook mechanism, where you can place a callback instead of a string path.

The callback can decide to return the code if encountered by require while working thru @INC.

The interface is a bit convoluted but it works. After adding the hook inside BEGIN you can call use or require deeply hidden inside foreign code and your "RAM modules" are installed.

quotes from the docs

    You can also insert hooks into the file inclusion system by putting Perl code directly into @INC. Those hooks may be subroutine references, array references or blessed objects. See "require" in perlfunc for details.

...

    You can also insert hooks into the import facility by putting Perl code directly into the @INC array. There are three forms of hooks: subroutine references, array references, and blessed objects. ...

edit

here some example code from an older discussion

in that case the code is fetched via HTTP, but it should be easy to to just fill in your RAM stuff instead.

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2025-11-14 05:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (70 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.