Skip to content

Instantly share code, notes, and snippets.

@hirose31
Forked from fujiwara/installed2cpanfile
Last active December 19, 2015 02:28
Show Gist options
  • Save hirose31/5883207 to your computer and use it in GitHub Desktop.
Save hirose31/5883207 to your computer and use it in GitHub Desktop.
$ perl installed2cpanfile > cpanfile
$ cpanm --installdeps .
#!/usr/bin/env perl
use strict;
use warnings;
use ExtUtils::Installed;
my $verbose = $ARGV[0] && $ARGV[0] eq '-v' ? 1 : 0;
my $i = ExtUtils::Installed->new;
for my $module (keys %$i) {
if ($module eq ":private:") {
#warn "[SKIP] $module is private\n";
next;
}
# if ($module =~ /-/) {
# warn "[SKIP] $module contains '-'\n";
# next;
# }
if ($module eq "Perl") {
next;
}
my $version = $i->{$module}->{version};
if (! $version) {
$module =~ s/-/::/g;
local $@;
eval "require $module";
if ($@) {
my $cause = $verbose ? ": $@" : "";
chomp $cause;
warn "[SKIP] failed to require $module $cause\n";
next;
}
if (! ($version = $module->VERSION)) {
warn "[SKIP missing VERSION: $module\n]";
next;
}
}
$version =~ s/^v//;
if (!$version || $version !~ /^\s*[\d._]*$/) {
warn "[SKIP] version of $module is not a number: [$version]\n";
next;
}
$module =~ s/-/::/g;
print "requires '$module', '$version';\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment