Why sometimes I can use a command to install Perl module, e.g.
perl -MCPAN -e "install Digest::MD5"
But sometimes can't?
e.g.
perl -MCPAN -e "install Archive::Zip"
>> Can't locate object method "install" via package "Archive::Zip" at -e line 1.
Are there any reason?
Thanks
Hmm, it looks like it is trying to use an indirect object method call
(that is it is trying to do this Archive::Zip->install() instead of
CPAN::install("Archive::Zip")). I wouldn't worry about it if I were
you, I would just use the new(ish) cpan command instead:
cpan Archive::Zip
This does the same thing
perl -MCPAN -e "install Archive:Zip"
should do.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
Since you're using double quotes, I assume that you're on Windows. I
suspect it has something to do with the way cmd is parsing the command
before passing it to perl.
If you enter the cpan shell and then issue install command, you can
avoid this problem.
e.g.,
this doesn't work, as you already know
C:\test>perl -MCPAN -e "install Archive::Zip"
Can't locate object method "install" via package "Archive::Zip" at -e
line 1.
this does work
C:\test>perl -MCPAN -e shell
cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support enabled
cpan> install Archive::Zip
CPAN: Storable loaded ok
Going to read C:\Perl\cpan\Metadata
Database was generated on Sun, 01 Mar 2009 11:26:52 GMT
Running install for module Archive::Zip
Running make for A/AD/ADAMK/Archive-Zip-1.26.tar.gz
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/A/AD/ADAMK/Archive-Zip-1.26.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
ftp://cpan-sj.viaverio.com/pub/CPAN/authors/id/A/AD/ADAMK/CHECKSUMS
CPAN: Compress::Zlib loaded ok
Checksum for C:\Perl\cpan\sources\authors\id\A\AD\ADAMK\Archive-
Zip-1.26.tar.gz ok
Scanning cache C:\Perl\cpan\build for sizes
Archive-Zip-1.26/
....
....
....
no matter I use single or double quote (on Linux), both does not
work...
what I want to do is issue the commands in a sh for job automation. I
don't want to enter the cpan shell and type onstall every time...
This is something I haven't noticed before:
> perl -MCPAN -MO=Deparse -e "install Digest::MD5"
install('Digest::MD5');
-e syntax OK
> perl -MCPAN -MO=Deparse -e "install Archive::Zip"
'Archive::Zip'->install;
-e syntax OK
The problem is that the CPAN module loads Archive::Zip itself, so that Perl then
recognizes the module name as a class instead of a simple bareword.
The easiest fix is to force the semantics by using parentheses:
> perl -MCPAN -MO=Deparse -e "install(Digest::MD5)"
and
> perl -MCPAN -MO=Deparse -e "install(Archive::Zip)"
both of which will work fine.
HTH,
Rob