gugod / App-perlbrew

Manage perl installations in your $HOME
https://perlbrew.pl
Other
720 stars 216 forks source link

Cannot import modules with `cpm`: `install-cpm` vs `install-cpanm` commands #797

Closed rwp0 closed 8 months ago

rwp0 commented 8 months ago

I can install and use modules after doing install-cpanm:

perlbrew install-cpanm

cpanm Path::Tiny

perl -M Path::Tiny

But I cannot use (import) modules after doing install-cpm successfully:

perlbrew install-cpanm

cpm install URI

perl -M URI

# Can't locate URI.pm in @INC

I'd prefer cpm to cpanm because of its non-verbosity and colors, but what am I doing wrong?

Do I need to do additional configuration manually after issuing the install-cpanm command for the cpm utility to install modules to usual paths or be the same as cpanm?

Not very familiar with it, and thinking perhaps I need to do some tweaks for cpm for the brewed perl to recognize the modules (if that's not done by default by perlbrew after doing install-cpm ).

Thanks

rwp0 commented 8 months ago

Seems like we need to use the -g option of the install command as documented in the SYNOPSIS (accessible with cpm --help)

# install module into current @INC instead of local/
> cpm install -g Module

Else the modules are being installed under the ~/local directory instead of under the ~/perl5 directory since the Perlbrew Perl looks at ~/perl5/perlbrew/perls/<PERL-NAME>/lib/site_perl/<PERL-VERSION>/ for third-party CPAN modules.

I think this could be documented somewhere in the README or elsewhere so that the users won't get confused.

smonff commented 8 months ago

You could also indicate the local directory explicitly:

perl -Ilocal -MURI

@rwp0

rwp0 commented 8 months ago

Thanks @smonff good to know.

I think it's better to indicate the full path here:

perl -I$HOME/local -MURI

It seems to me that cpm differs from cpan and cpanm by always using local::lib and thereby installing to local by default.

smonff commented 8 months ago

Yes, but local is not necessarily in the user's home. In my case, it's usually in the project's root directory during development. It may differ during deployment, where an absolute path might be useful.

It helps to keep each projects dependencies isolated, like npm and node_modules in the Nodejs world.

rwp0 commented 8 months ago

It helps to keep each projects dependencies isolated, like npm and node_modules in the Nodejs world.

I don't understand this part. How installing the modules in a central ~/local directory keeps them isolated per project (since each project is supposed to have its own directory)?

smonff commented 8 months ago

If you don't use the -g flag, it install dependencies to the current location.

rwp0 commented 8 months ago

If you don't use the -g flag, it install dependencies to the current location.

Oh yeah now I understand it

mkdir project
cd project
cpm install Path::Tiny
less ./local/lib/perl5/Path/Tiny.pm

Like npm install does.

Thanks a lot! 🙂