ADAMK-Release
view release on metacpan or search on metacpan
lib/ADAMK/Release.pm view on Meta::CPAN
package ADAMK::Release;
use 5.10.0;
use strict;
use warnings;
use Carp ();
use CPAN::Uploader 0.103003 ();
use Devel::PPPort 3.21 ();
use File::Spec::Functions 0.80 ':ALL';
use File::Slurp 9999.19 ();
use File::Find::Rule 0.32 ();
use File::Flat 1.04 ();
use File::ShareDir 1.03 ();
use File::LocalizeNewlines 1.12 ();
use GitHub::Extract 0.02 ();
use IO::Prompt::Tiny 0.002 ();
use Module::Extract::VERSION 1.01 ();
use Params::Util 1.00 ':ALL';
use Term::ReadKey 2.14 ();
use YAML::Tiny 1.51 ();
our $VERSION = '0.02';
use constant TOOLS => qw{
cat
chmod
make
touch
sudo
bash
};
use Object::Tiny 1.01 qw{
module
github
verbose
release
no_rt
no_changes
no_copyright
no_test
}, map { "bin_$_" } TOOLS;
######################################################################
# Constructor
sub new {
my $self = shift->SUPER::new(@_);
# Check module
unless ( _CLASS($self->module) ) {
$self->error("Missing or invalid module");
}
# Inflate and check the github object
if ( Params::Util::_HASH($self->github) ) {
$self->{github} = GitHub::Extract->new( %{$self->github} );
}
unless ( Params::Util::_INSTANCE($self->github, 'GitHub::Extract')) {
$self->error("Missing or invalid GitHub specification");
}
# Release options
$self->{release} = !!$self->{release};
# Find all of the command line tools
foreach my $tool ( TOOLS ) {
$self->{ "bin_" . $tool } = $self->which($tool);
}
return $self;
}
######################################################################
# Command Methods
sub run {
my $self = shift;
# Export from GitHub and change to the directory
my $pushd = $self->github->pushd;
unless ( $pushd ) {
$self->error(
"Failed to download and extract %s: %s",
$self->github->url,
$self->github->error,
);
}
# This is total bulldozer coding, there is no reason whatsoever why
# this stuff should be in seperate methods except that it provides
# a little cleaner logical breakup, and maybe I want to subclass this
# someday or something.
lib/ADAMK/Release.pm view on Meta::CPAN
}
sub move {
my $self = shift;
my $from = shift;
my $to = shift;
File::Flat->copy( $from => $to ) and return 1;
$self->error("Failed to move '$from' to '$to'");
}
sub remove {
my $self = shift;
my $path = shift;
if ( -e $path ) {
$self->sudo(
"rm -rf $path",
"Failed to remove '$path'"
);
}
return 1;
}
sub sudo {
my $self = shift;
my $message = pop @_;
my $cmd = join ' ', @_;
my $env = $self->env(
ADAMK_RELEASE => 1,
RELEASE_TESTING => $ENV{RELEASE_TESTING} ? 1 : 0,
AUTOMATED_TESTING => $ENV{AUTOMATED_TESTING} ? 1 : 0,
);
print "> (sudo) $cmd\n" if $self->verbose;
my $sudo = $self->bin_sudo;
my $rv = ! system( "$sudo bash -c '$env $cmd'" );
if ( $rv or ! @_ ) {
return $rv;
}
$self->error($message);
}
sub shell {
my $self = shift;
my $message = pop @_;
my $cmd = join ' ', @_;
my $env = $self->env(
ADAMK_RELEASE => 1,
RELEASE_TESTING => $ENV{RELEASE_TESTING} ? 1 : 0,
AUTOMATED_TESTING => $ENV{AUTOMATED_TESTING} ? 1 : 0,
);
print "> $cmd\n" if $self->verbose;
my $rv = ! system( "$env $cmd" );
if ( $rv or ! @_ ) {
return $rv;
}
$self->error($message);
}
sub env {
my $self = shift;
my %env = @_;
join ' ', map { "$_=$env{$_}" } sort keys %env;
}
sub error {
my $self = shift;
my $message = sprintf(shift, @_);
Carp::croak($message);
}
sub prompt {
my $self = shift;
return IO::Prompt::Tiny::prompt(@_);
}
sub password {
my $self = shift;
my $password = undef;
if ( defined $_[0] ) {
print "$_[0] ";
}
eval {
Term::ReadKey::ReadMode('noecho');
$password = <STDIN>;
};
Term::ReadKey::ReadMode(0);
return undef if not defined $password;
chomp($password);
return $password;
}
1;
__END__
=head1 NAME
ADAMK::Release -
=head1 DESCRIPTION
C<ADAMK::Release> is the backend behind the C<adamk-release> script that
is used to build distribution tarballs for modules with the minimalist
repository style.
=head1 AUTHORS
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
=head1 SEE ALSO
L<http://ali.as/>
=head1 COPYRIGHT
Copyright 2013 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
( run in 0.905 second using v1.01-cache-2.11-cpan-39bf76dae61 )