To address this error:
Trying to run a Perl script on Linux, I got an error: "Can't locate Devel/GlobalDestruction.pm”
cpanm
I use cpanm from Tatsuhiko Miyagawa.
Following the personal install guidelines in that document, this next section will install cpanm into ~/bin, which needs to be in your PATH.
cd ~/bin
curl -L https://cpanmin.us/ -o cpanm
chmod +x cpanm
which cpanm
Now use cpanm to install the missing library in a directory named local inside a given directory holding the original script, such as dir:
cd <dir>
cpanm -L local Devel::GlobalDestruction
To include the package installed in that directory,
use FindBin to locate the current local directory, and
use lib to locate your recently installed files.
Here is the code to add to the original script, located in dir
use FindBin qw( $Bin );
use lib “$Bin/local/lib/perl5”;
The cpanm code recursively installs all dependencies. In my session I got these two:
cpanm -L local Devel::GlobalDestruction
--> Working on Devel::GlobalDestruction
Fetching http://www.cpan.org/authors/id/H/HA/HAARG/Devel-GlobalDestruction-0.13.tar.gz ... OK
Configuring Devel-GlobalDestruction-0.13 ... OK
==> Found dependencies: Sub::Exporter::Progressive
--> Working on Sub::Exporter::Progressive
Fetching http://www.cpan.org/authors/id/F/FR/FREW/Sub-Exporter-Progressive-0.001011.tar.gz ... OK
Configuring Sub-Exporter-Progressive-0.001011 ... OK
Building and testing Sub-Exporter-Progressive-0.001011 ... OK
Successfully installed Sub-Exporter-Progressive-0.001011
Building and testing Devel-GlobalDestruction-0.13 ... OK
Successfully installed Devel-GlobalDestruction-0.13
2 distributions installed
As a small variation of the above
Change the cpanm argument from upper L [-L] to lower l [-l] to see if their is a difference in being complete, or not in the package dependency set.
Delete the local directory between those attempts to ensure that the packages installed are minimal.
A test
As an example use of the above, here is the modification to the 03_minusc.t test case that finds the new libraries in the directory into which I downloaded the libraries above into a directory named local:
The link with the original test:
http://cpansearch.perl.org/src/HAARG/Devel-GlobalDestruction-0.13/t/03_minusc.t
Here is the modification to the code:
use FindBin qw( $Bin );
use lib "$Bin/local/lib/perl5";
use Devel::GlobalDestruction;
Here is the output:
1..3
ok - Test properly running under minus-c
ok - BEGIN is not GD with -c
./test.pl syntax OK
ok - Final cleanup object destruction properly in GD
After reading Sinan’s post, I think my perl, used below, /opt/local/bin/perl, should be changed to the one he suggested /home/onlinetv/perl/bin/perl
Here is the test code with the modification:
#!/opt/local/bin/perl
BEGIN {
if ($ENV{DEVEL_GLOBALDESTRUCTION_PP_TEST}) {
unshift @INC, sub {
die 'no XS' if $_[1] eq 'Devel/GlobalDestruction/XS.pm';
};
}
}
{
package Test::Scope::Guard;
sub new { my ($class, $code) = @_; bless [$code], $class; }
sub DESTROY { my $self = shift; $self->[0]->() }
}
sub ok ($$) {
print "not " if !$_[0];
print "ok";
print " - $_[1]" if defined $_[1];
print "\n";
!!$_[0]
}
BEGIN {
require B;
B::minus_c();
print "1..3\n";
ok( $^C, "Test properly running under minus-c" );
}
use FindBin qw( $Bin );
use lib "$Bin/local/lib/perl5";
use Devel::GlobalDestruction;
BEGIN {
ok !in_global_destruction(), "BEGIN is not GD with -c";
}
our $foo;
BEGIN {
$foo = Test::Scope::Guard->new( sub {
ok( in_global_destruction(), "Final cleanup object destruction properly in GD" ) or do {
require POSIX;
POSIX::_exit(1);
};
});
}
PREFIX=/home/onlinetv/perl/usr
coming from? – Sinan Ünür May 2 '15 at 12:44unset PREFIX
, then ran cpan shell. But the error is still there. – user4035 May 2 '15 at 13:44cpan
. Get rid of the one you don't want – ikegami May 2 '15 at 16:03