gs / create_ebuild.pl

#!/usr/bin/env perl
#
# name:      automatically create ebuild for Perl module
# author:    Xu Xiaodong <xxdlhy@gmail.com>
# license:   GPL
# created:   2011 Feb 15
# modified:  2011 Nov 12
#

use strict;
use warnings;

use HTTP::Tiny;
use JSON::XS;
use autodie;

# Get module infomation, get_module_info($module)
sub get_module_info {
  my $module   = shift;
  my $url      = "http://api.metacpan.org/module/$module";
  my $http     = HTTP::Tiny->new;
  my $response = $http->get($url);
  my $content  = $response->{content};
  my $json     = JSON::XS->new;
  my $info_ref = $json->decode($content);

  return (
    $info_ref->{distribution}, $info_ref->{author},
    $info_ref->{version},      $info_ref->{abstract},
  );
}

# Create ebuild file, create_ebuild($module)
sub create_ebuild {
  my $module = shift;
  my ( $name, $author, $version, $abstract ) = get_module_info($module);
  my $ebuild = << "TEMPLETE";
# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=3

MODULE_AUTHOR=$author
MODULE_VERSION=$version
inherit perl-module

DESCRIPTION="$abstract"

LICENSE="perl 5"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

SRC_TEST="do"
TEMPLETE

  my $root_path = '/usr/local/portage/dev-perl';

  mkdir $root_path unless -d $root_path;
  chdir $root_path;

  mkdir $name;
  chdir $name;

  open my ($out_fh), '>', "$name-$version.ebuild";
  print $out_fh $ebuild;
  close $out_fh;

  system "ebuild", "$name-$version.ebuild", "manifest";
}

# Main program
sub run {
  my ($module) = @ARGV;

  die "Usage: $0 <module name>\n" unless $#ARGV == 0;
  create_ebuild($module);
}


run() unless caller;

__END__

=pod

=head1 NAME

create_ebuild.pl - Automatically create ebuild for Perl module

=head1 SYNOPSIS

create_ebuild.pl <module name>

=head1 AUTHOR

Xu Xiaodong <xxdlhy@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Xu Xiaodong.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

=cut
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.