Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Where to save module data

by stevieb (Canon)
on Oct 09, 2024 at 15:25 UTC ( [id://11162126]=note: print w/replies, xml ) Need Help??


in reply to Where to save module data

If the module is called under a service user, or it's ok for each user to have their own copy, I use the user's home directory for this. Here's an incomplete/pseudo example:

use File::HomeDir; my $home_dir = File::HomeDir->my_home; my $data_file = "$home_dir/api_data.json"; if (! -e $data_file || time() - (stat($data_file))[9] > 600) { # File doesn't exist or is older than 10 minutes ...get/update the file } ...do stuff with file

The module won't have access to the file/directory, but the user calling it will.

Update: This doesn't just work on Unix/MacOS. It also works on Windows. I use it in berrybrew.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2026-01-16 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (118 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.