Git-Wrapper
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Git/Wrapper.pm view on Meta::CPAN
use 5.006;
use strict;
use warnings;
package Git::Wrapper;
#ABSTRACT: Wrap git(7) command-line interface
$Git::Wrapper::VERSION = '0.048';
our $DEBUG=0;
# Prevent ANSI color with extreme prejudice
# https://github.com/genehack/Git-Wrapper/issues/13
delete $ENV{GIT_PAGER_IN_USE};
use File::chdir;
use File::Temp;
use IPC::Open3 qw();
use Scalar::Util qw(blessed);
use Sort::Versions;
use Symbol;
use Git::Wrapper::Exception;
use Git::Wrapper::File::RawModification;
use Git::Wrapper::Log;
use Git::Wrapper::Statuses;
sub new {
my $class = shift;
# three calling conventions
# 1: my $gw = Git::Wrapper->new( $dir )
# 2: my $gw = Git::Wrapper->new( $dir , %options )
# 3: my $gw = Git::Wrapper->new({ dir => $dir , %options });
my $args;
if ( scalar @_ == 1 ) {
my $arg = shift;
if ( ref $arg eq 'HASH' ) { $args = $arg }
elsif ( blessed $arg ) { $args = { dir => "$arg" } } # my objects, let me
# show you them.
elsif ( ! ref $arg ) { $args = { dir => $arg } }
else { die "Single arg must be hashref, scalar, or stringify-able object" }
}
else {
my( $dir , %opts ) = @_;
$dir = "$dir" if blessed $dir; # we can stringify it for you wholesale
$args = { dir => $dir , %opts }
}
my $self = bless $args => $class;
die "usage: $class->new(\$dir)" unless $self->dir;
return $self;
}
sub AUTOLOAD {
my $self = shift;
(my $meth = our $AUTOLOAD) =~ s/.+:://;
return if $meth eq 'DESTROY';
$meth =~ tr/_/-/;
return $self->RUN($meth, @_);
}
sub ERR { shift->{err} }
sub OUT { shift->{out} }
sub AUTOPRINT {
my $self = shift;
$self->{autoprint} = shift if @_;
return $self->{autoprint};
}
sub RUN {
my $self = shift;
delete $self->{err};
delete $self->{out};
my $cmd = shift;
my( $parts , $stdin ) = _parse_args( $cmd , @_ );
my @cmd = ( $self->git , @$parts );
my( @out , @err );
{
local $CWD = $self->dir unless $cmd eq 'clone';
my ($wtr, $rdr, $err);
local *TEMP;
if ($^O eq 'MSWin32' && defined $stdin) {
my $file = File::Temp->new;
$file->autoflush(1);
$file->print($stdin);
$file->seek(0,0);
open TEMP, '<&=', $file;
$wtr = '<&TEMP';
undef $stdin;
}
$err = Symbol::gensym;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.526 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )