Copy-From-Git

 view release on metacpan or  search on metacpan

lib/Copy/From/Git.pm  view on Meta::CPAN

use strict;

package Copy::From::Git;

use File::Basename;

our $VERSION = 0.0003_02;

sub new {
	my $class = shift;

	my $args = {
		server => 'guthub.com',
		path   => undef, 
		repo   => undef,
		branch => 'master',
		subdir => '.',
		user   => getlogin(),
		@_,
	};

	return bless $args => $class;
}

sub clone {
	my ($self, $target) = @_;

	$target = '/tmp/testing/' unless $target;

	unless( -d $target ){
		my $cmd;
		if( $self->{http} ){
			$cmd = sprintf "git clone -b %s %s%s/%s %s", $self->{branch}, $self->{http}, ${self}->{server}, ${self}->{path}, $target ;
		} else {
			$cmd = sprintf "git clone -b %s %s\@%s:%s/%s %s", $self->{branch}, $self->{user}, ${self}->{server}, ${self}->{path}, ${self}->{repo}, $target ;
		}
		print "Executing: [$cmd]\n";
		system( $cmd );
	} else {
		my $cmd = sprintf "cd %s && git pull", $target;
		print "Executing: [$cmd]\n";
		system( $cmd );
	}

	$self->{target} = $target;

}

sub cleanup {
	my ($self) = @_;

	print "Cleaning up $self->{target}..\n";
	system( "rm -rI $self->{target}" );
}

sub copy {
	my $self = shift;

	my @files = `find $self->{target} -type f`;
	chomp for @files;

	for my $k ( keys %{$self->{files}} ){
		print "Finding [$k]..\n";
		my $target = ${self}->{files}->{"$k"};
		my @f = grep { /$k/ } @files;

		#print "Target: [$target]\n";

		# We need to ensure that the target dir
		# exists for each of these files.
		for ( @f ){
			my ($filename, $directories, $suffix) = fileparse($_);
			#print "$filename => $directories .. ";

			# Check that $directories exists
			$directories =~ s/^$self->{target}//;
			#print "$directories\n";

			`mkdir -p ${target}/${directories}`
				unless -d "${target}/${directories}";

			`cp -v $_ ${target}/${directories}`;

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.904 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )