move helpers location to inside lib
[p5sagit/Distar.git] / lib / Distar / helpers / generate-license
diff --git a/lib/Distar/helpers/generate-license b/lib/Distar/helpers/generate-license
new file mode 100755 (executable)
index 0000000..0b3e9cc
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Software::LicenseUtils;
+use Getopt::Long qw(:config gnu_getopt);
+
+GetOptions(
+  "o|output=s"    => \(my $output = '-'),
+) or die("Error in command line arguments!\n");
+
+my ($authors, @licenses) = @ARGV;
+
+my $out;
+if ($output eq '-') {
+  $out = \*STDOUT;
+}
+else {
+  open $out, '>', $output
+    or die "Unable to write to $output: $!\n";
+}
+
+my %uniq;
+print { $out }
+  join "\n\n",
+  map { $_->new({holder => $authors})->license }
+  grep { !$uniq{$_}++ }
+  map { Software::LicenseUtils->guess_license_from_meta_key($_, 2) }
+  @licenses;