in reply to Where to save module data

Bod wrote:

But, over dinner, whilst tucking into roast pork and sprouts (one of my favourite vegetables), I pondered how to approach this if it was a module I intended to publish on CPAN. This module will never be published, but I can imagine plenty of reasons for CPAN modules to need to write files just for their own use.

Is there a standard way to handle this?
Can we be sure that the module will have write permissions on the directory where it resides?
Is there an environment variable common to all environments for a temporary directory that can be used for this sort of thing?

Despite that fact that I hate and loath sprouts, I am going to reply ;-)

By the time I post this reply you will undoubtedly have received several good suggestions, Bod. What I wanted to add is that there is a standard for such things. It goes by the term XDG Base Directory Specification - cited already by ysth in Re^3: Where to save module data. All flavors of Linux (probably) adhere to it, and the perl module File::HomeDir employs it, as well providing for equivalents in the Windows world.

The specification linked to above will answer several of your questions. Note that, with File::Homedir, only two of the methods provided will actually create directories for you (given the appropriate args). The other methods return undef if the cited directory does not already exist.

Oct 18, 2024 at 19:37 UTC
The open palm of desire
Wants everything, it wants everything
It wants soil as soft as summer
And the strength to push like spring
Paul Simon -> Further to Fly

Replies are listed 'Best First'.
Re^2: Where to save module data
by Bod (Parson) on Oct 18, 2024 at 23:07 UTC
    Despite that fact that I hate and loath sprouts, I am going to reply ;-)

    When I was young, I too hated sprouts...
    The older I get, the more I like them...to the point that I have become so old that they are one of my favourite vegetables, along with artichokes!

    What I wanted to add is that there is a standard for such things

    Thank you...

    That is precisely what my sprout inspired curiosity was looking for 👍