3

Perl newbie here with very little time and support to learn Perl but all the expectations from management to use it like a Perl Pro :)

I am using Perl (v5.30.2 by Larry Wall) under Cygwin (windows 10)

My developer issued a new script, that now uses a Perl module I didn't have.
They then sent me the .pm file (which they authored themselves and it is not on any online Perl repo).

I was unable to use CPAN to install that file into my Perl execution environment.

  1. Where should the .pm file be saved at? (please specify the exact folder)
  2. How to tell CPAN to install this file for usage? Ideally, a one-time affair, as I don't want to forget installing this file, if I have to do that every time I need to run the Perl script...
  • Just in case there may be any security concern from the dear answer-ers: There isn't any security concern here, this is all under an environment that has no connection to the internet.
DraxDomax
  • 1,008
  • 1
  • 9
  • 28
  • 2
    Place it in the same dir as the script and add `use FindBin qw( $RealBin ); use lib $RealBin;` to the script. – ikegami Jan 20 '21 at 17:19
  • 2
    If the module had an installer, it would place the script in the dir given by `perl -V:installsitelib` – ikegami Jan 20 '21 at 17:21
  • Tell your developer to document what needs to happen, and to provide a way to put everything as it needs to be. You're paying him to do his work, not us :) – brian d foy Jan 21 '21 at 10:04
  • @briandfoy I am a lowly QA guy, who even cares about us? :D Devs use mac (where this stuff is more-ready out of the box) and everyone else can "Jog On" (in lieu of a more appropriate but indecent phrase)... Ikegami's comments actually helped, but unveiled a bunch of dep's I can't sort out (DBD::Oracle, OCI, MakeFile, local::lib - and all have to be compatible versions, can't just have "any" package!) without specialist environment configuration knowledge... I am actually going to take your advice and report to management I can't do this, not with the machine given to me or lack of support... – DraxDomax Jan 21 '21 at 12:00
  • 2
    We care! Here are two ancient articles that I wrote but are relevant here [Creating Perl Application Distributions](https://www.drdobbs.com/web-development/creating-perl-application-distributions/184415995) and [Automating Distributions with scriptdist](https://www.drdobbs.com/web-development/creating-perl-application-distributions/184415995) – brian d foy Jan 21 '21 at 12:42

1 Answers1

2

A Perl module is just a file (or collection of files). You don't have to put them anywhere special, but you need to tell Perl where to find them.

When you call use or require with a bareword, Perl translates that module name, like Some::Module, into Some/Module.pm (or whatever is appropriate for your system. Anyone still using VMS?).

Once it has the filename form of the module, it looks for that subpath in the directories in @INC. It tries the first directory. If it doesn't find it it moves on to the next, and so on down the line. These directories are decided when someone configures and installs Perl. And, before v5.26, it included the current working directory (see v5.26 removes dot from @INC and Doesn't Perl include current directory in @INC by default? )

But, you can tell Perl where else to look. perlfaq8 has How do I add a directory to my include path (@INC) at runtime?. ikegami also showed FindBin in the comments (How do I add the directory my program lives in to the module/library search path?).

Beyond that, you can tell require to load a path, although you then need to ensure that the program can find that path even if someone runs it from another directory

 require './this_file/over/here';
 require '/usr/local/lib/this_file/over/here';
brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • In the comments, OP stated that the module has a bunch of includes that aren't installed (on his system that wasn't net connected), all of which have to be specific versions. I know that's not part of the original question, but you might want to head off the inevitable question update in advance. – stevieb Jan 21 '21 at 14:45
  • My answer for that is the same. Make the developer provide a professional, industry standard work product. – brian d foy Jan 21 '21 at 20:12