Skip to content

Instantly share code, notes, and snippets.

@typhonius
Last active March 22, 2016 03:56
Show Gist options
  • Save typhonius/8d75a563a2f8bdef648f to your computer and use it in GitHub Desktop.
Save typhonius/8d75a563a2f8bdef648f to your computer and use it in GitHub Desktop.
Super delicious perl script to get a list of modules from d.o and select one at random for the user to port to Drupal 8. Also it's perlcritic brutal approved!
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
use Scalar::Util qw(looks_like_number);
our $VERSION = 1.337;
sub gimmeamodule {
my $moduledata = get(
'http://drupalcode.org/sandbox/greggles/1481160.git/blob_plain/refs/heads/master:/allmodules.txt'
);
if ($moduledata) {
my @modules = split /\n/sxm, $moduledata;
my $linecount = scalar @modules;
if ( !$linecount ) {
return;
}
my $count;
if ( !$ARGV[0] || !looks_like_number($ARGV[0]) ) {
$count = 1;
} else {
$count = $ARGV[0]
}
my $rand;
my @array;
for (0..$count) {
$rand = int rand $linecount;
push @array, "You should port $modules[$rand]!\nFind out more here https://drupal.org/project/$modules[$rand]\n";
}
return @array;
}
return;
}
my @return = gimmeamodule();
if (@return) {
exit 1 if !print @return;
}
else {
die "Unable to get/parse module data\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment