I'm trying to install Gitolite as in the http://wiki.dreamhost.com/Gitolite
I get the error like :
"make_path" is not exported by the File::Path module
Can't continue after import errors at gitolite/src/gl-system-install line 5
BEGIN failed--compilation aborted at gitolite/src/gl-system-install line 5.
There is a problem with perl but I could not find solution yet.
server capabilities
/usr/local/bin/perl
perl v5.10.0
make_path was introduced in File::Path 2.06_05. You must be using an older version (Perl 5.10.0 came with File::Path 2.04). Upgrade File::Path (or upgrade Perl, since 5.10 is no longer supported).
At press time, gl-system-install calls make_path in one place, in the sub that begins at line 75:
sub check_dirs {
for my $dir ( $bin_dir, $conf_dir, $hooks_dir ) {
die "$dir should be an absolute path\n" unless $dir =~ m(^/);
make_path($dir);
-d $dir or die "$dir does not exist and could not be created\n";
}
}
This particular usage is call-compatible with mkpath instead. You don’t have to install a new File::Path module. Change line 5 of gl-system-install to
use File::Path qw(mkpath);
and line 78 to
mkpath($dir);
I encountered the same situation within the last week. After making the changes above, you can follow gitolite’s installation instructions with no further snags.
Update: This issue is now fixed in the gitolite repository.
make_path is only available in File::Path 2.07. I'm not sure if it's your problem or not, but you might try updating File::Path:
cpan File::Path
or
cpanp i File::Path
Related
I have made my own perl modules(pm files),named test.pm
package test;
use Exporter;
use strict;
use File::Basename qw(basename dirname);
use Cwd qw(abs_path);
use File::Path qw(make_path);
use FindBin qw($Bin $Script);
BEGIN {
our #ISA = qw(Exporter);
our #EXPORT = qw(mkdirOrDie);
our $VERSION = 1.0;
}
sub mkdirOrDie
{
my ($dir) = #_ ;
if(!-d $dir){
make_path($dir);
$dir=abs_path($dir);
# timeLog("Directory Created: $dir");
}
}
and I tried to install this module as follows,
h2xs -AX -n test
perl Makefile.PL
make
make install
there is no error,and I copy the test.pm to /usr/lib64/perl5/5.10.0/,but when i call sub function using test, an error has occurred,
Undefined subroutine &main::mkdirOrDie called at /to/my/path/main.pl line 92
is there something i ignored?
It's unclear at which point things started to go wrong for you.
Firstly, test.pm is a bad name for a Perl module. Perl modules should have names that begin with upper case letters (and Test.pm is already taken).
You should run h2xs before writing your code - as it generates a module skeleton for you fill in. I hope it hasn't overwritten your code with an almost empty file! It's also worth noting that most people stopped using h2xs many years ago. These days we have tools like Module::Starter.
Then, running, make install (which you need to do with root permissions - so usually with sudo) is what installs your module into the system libraries. There should be no need to run that cp command afterwards.
As for why your code doesn't find the module, there are many possible reasons. Are you using Perl 5.10 or do you have other Perl versions installed? What does the code look like that you are trying to use? Does test.pm still include the code you think it does?
Need more information to be much help here.
I created a perl script that includes the Switch module.
hello_world.pl
use strict;
use warnings;
use Switch;
use Data::Dumper;
my $var = "Hello World\n";
print Dumper($var);
if I launch perl hello_world.pl everything works fine. But if I pack my script with pp hello_world.pl and than launch ./a.out it gives me back this error:
Can't locate Switch.pm in #INC (you may need to install the Switch module) (#INC contains: CODE(0x7fb2631e6a88) /var/folders/rb/2b5sbs355n57svwzjjh7cb9c0000gn/T/par-6967676c6f62616c33/cache-710e967842eb844ab8d6fe5f46968c1b6f49e019/inc/lib /var/folders/rb/2b5sbs355n57svwzjjh7cb9c0000gn/T/par-6967676c6f62616c33/cache-710e967842eb844ab8d6fe5f46968c1b6f49e019/inc CODE(0x7fb262988de0) CODE(0x7fb262989930)) at script/hello_world.pl line 3.
BEGIN failed--compilation aborted at script/hello_world.pl line 3
$ corelist Switch
Data for 2016-05-09
Switch was first released with perl v5.7.3, deprecated (will be CPAN-only) in v5.11.0 and removed from v5.13.1
Switch was never a good idea. It's a source filter which means it's a clever party trick but shouldn't be used in production code. For that reason it has removed from Perl several versions ago.
I suspect that you are running your packaged program on a more recent version of Perl than the unpackaged version - one that no longer includes Switch.
You can install Switch on your target system or you can work out how to get pp to include the module in the package. But the best solution is to rewrite the code to stop using Switch.
You can try to force the modules to be included, with -M option:
pp -M Switch -M YAML ...
Seems as if depending on the version of perl, autodie masks some syntax-errors.
In Perl 5.16.0:
$ perlbrew use 5.16.0
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm
String found where operator expected at check_netapp_pro/lib/Il/Nagios/test/xx.pm line 10, near "croak "stop""
(Do you need to predeclare croak?)
syntax error at check_netapp_pro/lib/Il/Nagios/test/xx.pm line 10, near "croak "stop""
check_netapp_pro/lib/Il/Nagios/test/xx.pm had compilation errors.
But in 5.10.1:
$ perlbrew use 5.10.1
$ perl -c check_netapp_pro/lib/Il/Nagios/test/xx.pm
check_netapp_pro/lib/Il/Nagios/test/xx.pm syntax OK
The module xx.pm is:
package Il::Nagios::Store::Attribute;
use feature ':5.10';
use strict;
use warnings;
use autodie;
#use Carp;
croak "stop" if 0;
1;
__END__
The confusing part is that on some servers (e.g. CentOS 6.5, perl 5.10.1) the absence of use Carp; stops script execution even if use autodie; is present in the module.
Can anyone shed some light on this? How would you unit-test against such errors? (Test::Strict did not detect the missing use Carp; statement).
Thanks to the comment from #i-alarmed-alien I could quickly determine the reason:
On my 5.10.1 perlbrew installation autodie is installed with version 2.06_01, the newer installation (perl 5.16.0) is using autodie in version 2.10 where a bug had been fixed, which leaked the Carp functions.
Just for the records: To determine the version of autodie (or any other module) just type
cpan -D autodie
Is there a smart way to detect whether a certain Perl module has been installed in your system?
My old sutpid way is to write a Perl script in which the only thing I do is just to use the module. If nothing croaks when I run the detect script, then I know the module has been installed, although I still don't know which version and where the module has been installed .
thanks in advance.
Something like:
perl -MModule -e 'print "$Module::VERSION\n"' 2>/dev/null || echo "Not installed"
would give you the version of a given module, or tell you it isn't installed. Usage would look like:
perl -MXML::Parser -e 'print "$XML::Parser::VERSION\n"' 2>/dev/null || echo "Not installed"
To find the module path, you could examine #INC to find possible locations, or you could perhaps look into perlwhich. There is also pmpath from pmtools.
The shortest thing I know of that doesn't involve a script or shell alias:
$ perl -MFoo::Bar\ 99
Foo::Bar version 99 required--this is only version 1.234.
(or the usual message about not being in #INC if it's not installed)
For the curious, this is the same as perl -e 'use Foo::Bar 99'.
instmodsh
NAME
instmodsh - A shell to examine installed modules
SYNOPSIS
instmodsh
DESCRIPTION
A little interface to ExtUtils::Installed to examine installed modules, validate your packlists and even create a tarball from an installed module.
SEE ALSO
ExtUtils::Installed
Here's a program which does that:
#!/usr/bin/perl
# testmod - test to see if a module is available
use strict;
use warnings;
my $mod = (shift #ARGV) || die "usage: $0 module\n";
# convert module-name to path
my $file = $mod;
$file =~ s{::}{/}gsmx;
$file .= '.pm';
# Pull in the module, if it exists
eval { require $file }
or die "can't find module $mod\n";
# Get the version from the module, if defined
my $ver;
{ no strict 'refs';
$ver = ${$mod . "::VERSION"} || 'UNKNOWN';
}
# And its location
my $from = $INC{$file};
print "module $mod is version $ver loaded from $from\n";
Use pmvers. Like the name suggests, it shows the version of an installed module. If a module is not installed, it fails with the familiar error message: Can't locate … in #INC (#INC contains: …)
Use pmpath from the same distribution to find a module's installation path.
I use these bash function/Perl oneliners to find the version number and location of Perl modules:
# equivalent to perldoc -l <module>
perlwhere() {
perl -wle'eval "require $ARGV[0]" or die; ($mod = $ARGV[0]) =~ s|::|/|g; print $INC{"${mod}.pm"}' $1
}
perlversion() {
perl -M$1 -wle'print $ARGV[0]->VERSION' $1
}
: [ether ~].2$; perlwhere Test::More
/usr/lib/perl5/5.8.8/Test/More.pm
: [ether ~].2$; perlversion Test::More
0.94
I don't know if there is any smart way for this. But what I usually
do is to make use of '-l' or '-m' option of perldoc. For example :
%perldoc -l XML::Simple
and the output is something like below,which is the full path of module file
.../lib/XML/Simple.pm
The advantage with this approach compared to yours is that, if the module is installed
the output contains the path for module location. However when the module is not
installed
or if it doesn't has a perldoc the error message shown is "No documentation found for ...",
making it impossible to distinguish if the error is due to missing module or missing
documentation. In such scenario the -m option becomes handy since it prints entire
contents of the file along with the path.
The pmvers utility and the other pmtools will do what you need. Otherwise here is a one-liner to find a module version:
perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::Module
If you're looking for a cross-platform CLI (Linux, OSX, Windows), consider my whichpm utility; e.g.:
# Locate the Data::Dumper module, and also print
# version information and core-module status.
$ whichpm -v Data::Dumper
Data::Dumper 2.145 core>=5.005 /usr/lib/perl/5.18/Data/Dumper.pm
It can also find accidental duplicates and list all installed modules.
If you happen to have Node.js / io.js installed, you can install it from the npm registry:
[sudo] npm install whichpm -g
For manual installation instructions and more, see the repo; here's a direct download link to the latest version (will stay current).
How do you find the version of an installed Perl module?
This is in an answer down at the bottom, but I figure it important enough to live up here. With these suggestions, I create a function in my .bashrc
function perlmodver {
perl -M$1 -e 'print "Version " . $ARGV[0]->VERSION . " of " . $ARGV[0] . \
" is installed.\n"' $1
}
Most modules (especially ones from The CPAN) have a $VERSION variable:
perl -MSome::Module -le 'print $Some::Module::VERSION'
Why are you trying to get the version of the module? Do you need this from within a program, do you just need the number to pass to another operation, or are you just trying to find out what you have?
I have this built into the cpan (which comes with perl) with the -D switch so you can see the version that you have installed and the current version on CPAN:
$ cpan -D Text::CSV_XS
Text::CSV_XS
-------------------------------------------------------------------------
Fast 8bit clean version of Text::CSV
H/HM/HMBRAND/Text-CSV_XS-0.54.tgz
/usr/local/lib/perl5/site_perl/5.8.8/darwin-2level/Text/CSV_XS.pm
Installed: 0.32
CPAN: 0.54 Not up to date
H.Merijn Brand (HMBRAND)
h.m.brand#xs4all.nl
If you want to see all of the out-of-date modules, use the -O (capital O) switch:
$ cpan -O
Module Name Local CPAN
-------------------------------------------------------------------------
Apache::DB 0.1300 0.1400
Apache::SOAP 0.0000 0.7100
Apache::Session 1.8300 1.8700
Apache::SizeLimit 0.0300 0.9100
Apache::XMLRPC::Lite 0.0000 0.7100
... and so on
If you want to see this for all modules you have installed, try the -a switch to create an autobundle.
VERSION is a UNIVERSAL method of all Perl classes. You can use it to get the module version (if it has been set which it usually has).
Here is a one liner where you only have to add the module name once:
perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Some::Module
There is a less-typing trick, that works provided your module doesn't have something insane like a Unix timestamp as a version number.
perl -MFoo::Bar\ 9999
This works because what it translates to is
use Foo::Bar 9999;
i.e. a version of Foo::Bar that's at least version 9999 or newer.
And what you get is
Foo::Bar version 9999 required--this is only version 1.1.
BEGIN failed--compilation aborted.
(Neat trick I learned from Matt Trout.)
If you are lucky, the module will have a package variable named $VERSION:
$ perl -MCPAN -e 'print "$CPAN::VERSION\n"'
1.9205
This is needed for modules to be distributed on CPAN, but internally developed modules might follow a different convention or none at all.
Thanks for the answers! I've created a function in my .bashrc to easily find the version of a Perl module:
function perlmodver {
perl -M$1 -e 'print $ARGV[0]->VERSION . "\n"' $1
}
Easiest to remember and most robust version for me:
perl -e 'use Search::Elasticsearch; print $Search::Elasticsearch::VERSION;'
Check out the pmtools scripts on CPAN. If you're using a Debian(-based) distro, there's also a handy pmtools package. This includes a script "pmvers" that tells you a module's version. It's quite handy.
It does something similar to the various one-liners folks posted, but it's a bit smarter about error handling, and can give you the version of more than one module at once.
I wrote a small script to report that: perlver.
This is a simple little tool that
tells you what version of a module you
have installed, and where the .pm file
is located. It also ensures the module
can be loaded successfully. It
automatically converts ‘-’, ‘/’, or
‘\’ to ‘::’, so you can use a pathname
or distribution name instead of the
canonical module name.
It assumes that the module defines a $VERSION. If the module doesn't define a $VERSION, it will still tell you where the .pm file is, so you can examine it manually. You can also check several modules at once:
$ perlver CPAN DBD-Pg Getopt::Long
CPAN 1.7602 is
/usr/lib/perl5/5.8.8/CPAN.pm
DBD::Pg 1.49 is
/usr/lib/perl5/vendor_perl/5.8.8/i686-linux/DBD/Pg.pm
Getopt::Long 2.36 is
/usr/lib/perl5/vendor_perl/5.8.8/Getopt/Long.pm
In addition, for modules that use Exporter.pm, you can get this information with this trick:
perl -MSome::Module=99999 -ex
Some::Module version 99999 required--this is only version 1.9205 at ...
For modules that don't use Exporter.pm, a slightly longer trick reports the same information:
perl -e'use Some::Module 99999'
Some::Module version 99999 required--this is only version 1.9205 at ...
We have the system perl (/usr/bin/perl) in Solaris 10, and above solutions are useless. Some of them report "module.pm is not installed", some of them have no output.
Here is the code which is helpful, which can list all modules and their version.
#!/usr/bin/perl
use strict;
use ExtUtils::Installed;
my #modules;
my $installed = ExtUtils::Installed->new();
if (scalar(#ARGV) > 0) {
#modules = #ARGV;
} else {
#modules = $installed->modules();
}
print "Module\tVersion\n";
foreach (#modules) {
print $_ . "\t" . $installed->version($_) . "\n";
}
You can also take a look at App::module::version
$ module-version
The version of App::module::version in /home/yourself/perl5/lib/perl5 is 1.004