3

Sorry if this is very newb question, I promise I did try this on my own.

As I develop a perl prototype I keep installing new CPAN modules I wish to use for the prototype to my local perl. I want to ensure when this program is deployed all these CPAN modules I'm using are installed on the production box as well.

I don't want to keep track of every new CPAN module I install during development and manually install each on production, I want to run a command and have all the appropriate modules loaded. In java world I would use something like Maven to list these dependencies and trust maven to handle fetching and ensuring my libraries are available. Does Perl have the equivalent?

I would kind of expect I can point cpan to my program and it could infer which modules are needed with basic static analysis and install them on the fly, but I haven't found the program or syntax to do so. can anyone point me to

dsollen
  • 6,046
  • 6
  • 43
  • 84
  • `cpan` will fetch and install the dependencies when you install your [package](http://search.cpan.org/perldoc?ExtUtils::MakeMaker), though you will need to specify the immediate dependencies. – ikegami Jan 08 '16 at 17:33
  • 1
    Static analysis can't do this because of `eval`, among other things. You can get close with some of the tools mentioned in [How do I find the module dependencies of my Perl script?](http://stackoverflow.com/q/358891/176646), but if you want to make sure dependencies are installed when you install your code, you need to list them in the Makefile.PL or Build.PL for your distribution. – ThisSuitIsBlackNot Jan 08 '16 at 17:34
  • Not exactly a dupe, but you might find the answers to [this question](http://stackoverflow.com/questions/7664829/can-a-perl-script-install-its-own-cpan-dependencies) useful. – Ilmari Karonen Jan 08 '16 at 17:35
  • `print Dumper \%INC`? – Sobrique Jan 08 '16 at 17:36
  • The solutions in the question ThisSuitIsBlackNot linked and the solution Sobirque presented specify way too much. For most scripts, best to look at the `use` statements, and refine as needed (e.g. if you tell DBI to load a specific database driver). – ikegami Jan 08 '16 at 18:18
  • 1
    You put your dependencies in your `Makefile.PL` (or `Build.PL`) file for your distribution... see the `CONFIGURE_REQUIRES`, `BUILD_REQUIRES` and `PREREQ_PM` sections in this example: [Makefile.PL](https://metacpan.org/source/STEVEB/Mock-Sub-1.01/Makefile.PL). The `0` beside each name is the version number required. Specifying `0` literally means any version of the module will work. – stevieb Jan 08 '16 at 18:25
  • 2
    It sounds like you want a dependency management tool, e.g., [Carton](https://metacpan.org/pod/Carton). – Matt Jacob Jan 08 '16 at 19:16
  • 2
    You can specify dependencies for your app using [cpanfile](/a/31329070/293652) – Grant McLean Jan 09 '16 at 02:14

1 Answers1

1

The easiest way to do this is to load Webmin, which will report both native cpan modules, and modules loaded via yum or apt-get. Deploying the install is another discussion.

Curt Evans
  • 346
  • 2
  • 4
  • Thank you for this suggestion. I'm a little turn here, I very much appreciate your answer, but it doesn't fully answer the question, since you admitted to skipping over deploying. At the same time I feel the comments above finish answering the question, but can't select them as an answer... If you wanted to modify your answer to even briefly touch on the deployment options already mentioned in the comments above I would love to award you the answer though and finally close this :) In the meantime I'm going to go peak at webmin :) – dsollen Mar 29 '16 at 16:41
  • How you deploy depends on your target, and this is too complex to answer generically. You will need to create a script that detects the environment and tests for the modules by trying to install them one at a time. It will be different for Centos and Ubuntu. You do not want to load cpan modules over a package module, but you will need to use cpan to load modules that don't have a vendor package. – Curt Evans Mar 30 '16 at 19:11