1

I have a machine using some Perl programs with personnal packages, theses packages are in /home/user/libs/ , there are PM files

the package program start like this :

    package Connexion;
use vars qw(@ISA @EXPORT);
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw($prompt_foundry $variable);

the mains programs use package like this : use Connexion

So I want to now how this packages are installed (something like path variable ?? or how), how to list theme all, and how to install theme in new machine who already has Perl.

Thank you in advance.

mbooma
  • 65
  • 5
  • 1
    https://stackoverflow.com/q/2526804/10971581 – jhnc Jul 15 '23 at 23:53
  • *"the main program use the package like this : use Connexion"* : To clarify your question, please give a minimal runnable example of the main program, see [mcve] for more information – Håkon Hægland Jul 16 '23 at 06:34
  • *"I have a machine using some Perl programs with personal packages"* Personal packages without a [`Makefile.PL`](https://metacpan.org/pod/ExtUtils::MakeMaker) or [`Build.PL`](https://metacpan.org/pod/Module::Build) script are usually installed by simply copying them into some directory and then setting either the environment variable [`PERL5LIB`](https://perldoc.perl.org/perlrun) or alternatively using [`@INC`](https://perldoc.perl.org/variables/@INC) (e.g. `use lib`) or `-I` command line switch, see https://perldoc.perl.org/perlrun. Can you try to find out which of these you are using? – Håkon Hægland Jul 16 '23 at 06:58
  • [this post](https://stackoverflow.com/a/54433246/4653379) could also be useful. (The one I find easily -- there's _a lot_ more there) – zdim Jul 16 '23 at 07:31

1 Answers1

1

So I want to now how this packages are installed

I think you are asking how Perl locates the modules. It searches for them in the path listed in @INC. See How is Perl's @INC constructed? which has a great answer.


how to list theme all

Add the following to your program:

END {
   use v5.14;
   for my $qfn ( sort keys %INC ) {
      my $mod = $qfn =~ s{\.pm\z}{}r =~ s{/}{::}rg;
      say "$mod: $INC{ $qfn }";
   }
}

Then run it. This will list all the modules loaded by the program, and where they are located. There's probably a Devel:: module that does the same thing.


and how to install theme in new machine who already has Perl.

If it's just a .pm file, you likely just need to copy it into a directory in @INC.

If this module is specific to the program, I would do the following:

  1. Rename the module to My::Connexion (to avoid conflict with any same-named module on CPAN).

  2. Organize the project as follows:

    bin/script.pl
    lib/My/Connexion.pm
    
  3. Add the following to script.pl:

    use FindBin qw( $RealBin );
    use lib "$RealBin/../lib";
    

    This will allows the script (and modules used by the script) to find the module.

ikegami
  • 367,544
  • 15
  • 269
  • 518