Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Where to put data that goes with a module?

by swl (Vicar)
on Jul 02, 2020 at 04:36 UTC ( #11118781=note: print w/replies, xml ) Need Help??

in reply to Where to put data that goes with a module?

Have a look at File::ShareDir and File::ShareDir::Install.

  • Comment on Re: Where to put data that goes with a module?

Replies are listed 'Best First'.
Re^2: Where to put data that goes with a module?
by BillKSmith (Monsignor) on Jul 02, 2020 at 15:25 UTC
    I have been planning on asking a similar question. In my case, I have an old .pl script which I still occasionally find useful. It requires a large number of sound (.wav) files which it plays by passing their path to "Windows Media Player" with exec. (Because of changes to the Player, it only works reliably on Windows XP. I hope to fix that.) Your suggestion to use build tools to manage the sound files seems like overkill. I have never even attempted to use Makefile.PL and have had only limited success with Build.PL.

      Yes, it might well be overkill for many applications. If you have a standalone script that is not going onto CPAN then it's just as easy to add an adjacent data directory to an archive.

Re^2: Where to put data that goes with a module?
by Lady_Aleena (Priest) on Aug 26, 2020 at 18:28 UTC

    Hi. I know it has been almost two months since I asked this, but I got frustrated then, so decided to let this sit for a while. So now I have calmed down a bit, I can dig in.

    So, today I decided to give File::ShareDir a go on the command line, and I got the answer I was looking for initially. The main directory for external files a module needs is lib/auto. So now I know where to put the external data files and can use File::ShareDir to hopefully get them. I have not tried this yet but will shortly. Here is what I think the top of my module will look like, in this case I am using one of my favorites, Random::Color.

    package Random::Color; use v5.10.0; use strict; use warnings; use Exporter qw(import); use File::ShareDir qw(module_dir); use Fancy::Rand qw(fancy_rand); use Fancy::Open qw(fancy_open); our $VERSION = '1.000'; our @EXPORT_OK = qw(random_color); my $directory = module_dir('Random::Color'); my @Crayola_crayons = fancy_open("$directory/Crayola_crayon_colors.txt +");; my @MandMs = fancy_open("$directory/MandMs_colors.txt");

    Also, I am assuming when I go to package Random::Color the file list inside the package will be something like this.

    • Random-Color
      • Changes
      • ignore.txt
      • Makefile.PL
      • MANIFEST
      • README
      • lib
        • auto
          • Random
            • Color
              • Crayola_crayon_colors.txt
              • MandMs_colors.txt
        • Random
          • Color.pod
      • t
        • 00-load.t
        • manifest.t
        • pod-coverage.t
        • pod.t
      • xt
        • boilerplate.t

    Am I on the right track here? I got the base of this structure from Discipulus's tutorial.

    As an aside, I finally started using git because of that tutorial. How to use git was explained very well there. I am so very grateful for it!

    Update: I tried it, it works as expected, I'm happy! Thank you for the recommendation.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

      Good to hear it works.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-03-22 03:45 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.