Skip to content

Instantly share code, notes, and snippets.

@thaljef
Created May 3, 2014 03:01
Show Gist options
  • Save thaljef/52840fd60dfabc94f151 to your computer and use it in GitHub Desktop.
Save thaljef/52840fd60dfabc94f151 to your computer and use it in GitHub Desktop.
Dump a cpanfile into targets for Pinto
#!/usr/bin/env perl
# USAGE: cpanfile-dumper path/to/cpanfile | pinto -r path/to/repo pull
use strict;
use warnings;
use Module::CPANfile;
my $file = shift or die 'Must specify a cpanfile';
my $cpanfile = Module::CPANfile->load($file);
my @types = qw(requires recommends suggests);
my @phases = qw(configure build test runtime develop);
my $prereqs = $cpanfile->prereqs->merged_requirements( \@phases, \@types )->as_string_hash;
for my $module (sort keys %{ $prereqs }) {
my $version_spec = $prereqs->{$module};
$version_spec =~ s/\s//g; # Remove whitespace
$version_spec = "~$version_spec" unless $version_spec =~ m/[^v.\d_]/;
print $module . $version_spec . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment