From: Vincent Pit Date: Wed, 24 Feb 2010 16:51:36 +0000 (+0100) Subject: Less namespace pollution X-Git-Tag: v0.07~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=20ecc90aa6c17a07fd1200d0bf72d5918e53e106;p=perl%2Fmodules%2Frgit.git Less namespace pollution File::Spec is required instead of File::Spec::Functions. --- diff --git a/Makefile.PL b/Makefile.PL index 4604f22..8eec1e2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -9,13 +9,13 @@ my $dist = 'rgit'; (my $name = $dist) =~ s{-}{::}g; my %PREREQ_PM = ( - 'Carp' => 0, - 'Cwd' => 0, - 'Exporter' => 0, - 'File::Find' => 0, - 'File::Spec::Functions' => 0, - 'POSIX' => 0, - 'base' => 0, + 'Carp' => 0, + 'Cwd' => 0, + 'Exporter' => 0, + 'File::Find' => 0, + 'File::Spec' => 0, + 'POSIX' => 0, + 'base' => 0, ); my %META = ( @@ -23,14 +23,14 @@ my %META = ( 'ExtUtils::MakeMaker' => 0, }, build_requires => { - 'Cwd' => 0, - 'ExtUtils::MakeMaker' => 0, - 'Exporter' => 0, - 'File::Spec::Functions' => 0, - 'File::Temp' => 0, - 'POSIX' => 0, - 'Test::More' => 0, - 'base' => 0, + 'Cwd' => 0, + 'ExtUtils::MakeMaker' => 0, + 'Exporter' => 0, + 'File::Spec' => 0, + 'File::Temp' => 0, + 'POSIX' => 0, + 'Test::More' => 0, + 'base' => 0, %PREREQ_PM, }, recommends => { diff --git a/bin/rgit b/bin/rgit index c791124..fc9a1f7 100755 --- a/bin/rgit +++ b/bin/rgit @@ -3,10 +3,10 @@ use strict; use warnings; -use Carp qw/croak/; -use Config qw/%Config/; -use Cwd qw/cwd/; -use File::Spec::Functions qw/catfile path/; +use Carp qw/croak/; +use Config qw/%Config/; +use Cwd qw/cwd/; +use File::Spec (); # catfile, path use App::Rgit; use App::Rgit::Utils qw/:levels/; @@ -46,8 +46,8 @@ setpgrp 0, 0 if $Config{d_setpgrp}; my $git = $ENV{GIT_EXEC_PATH}; unless (defined $git) { - for (path) { - my $g = catfile $_, 'git'; + for (File::Spec->path) { + my $g = File::Spec->catfile($_, 'git'); if (-x $g) { $git = $g; last; @@ -191,7 +191,7 @@ Add a remote to all repositories in "/foo/bar" to their bare counterpart in C, L, L, L, L, L and L. +The core modules L, L, L, L, L, L and L. =head1 AUTHOR diff --git a/lib/App/Rgit/Config.pm b/lib/App/Rgit/Config.pm index 2ac22b2..7a247eb 100644 --- a/lib/App/Rgit/Config.pm +++ b/lib/App/Rgit/Config.pm @@ -3,9 +3,9 @@ package App::Rgit::Config; use strict; use warnings; -use Carp (); -use Cwd qw/abs_path/; -use File::Spec::Functions qw/canonpath/; +use Carp (); # confess +use Cwd (); # abs_path +use File::Spec (); # canonpath use App::Rgit::Repository; use App::Rgit::Utils qw/:levels/; @@ -46,7 +46,7 @@ sub new { my $root = $args{root}; return unless defined $root and -d $root; - $root = canonpath abs_path $root; + $root = File::Spec->canonpath(Cwd::abs_path($root)); my $git = $args{git}; return unless defined $git; @@ -58,7 +58,7 @@ sub new { } else { return unless -x $git; } - $git = canonpath abs_path $git; + $git = File::Spec->canonpath(Cwd::abs_path($git)); my $conf = 'App::Rgit::Config::Default'; eval "require $conf; 1" or Carp::confess("Couldn't load $conf: $@"); diff --git a/lib/App/Rgit/Repository.pm b/lib/App/Rgit/Repository.pm index 0ca5e94..a921576 100644 --- a/lib/App/Rgit/Repository.pm +++ b/lib/App/Rgit/Repository.pm @@ -3,9 +3,9 @@ package App::Rgit::Repository; use strict; use warnings; -use Cwd qw/cwd abs_path/; -use File::Spec::Functions qw/canonpath catdir splitdir abs2rel/; -use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT/; +use Cwd (); # cwd, abs_path +use File::Spec (); # canonpath, catdir, splitdir, abs2rel +use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT/; BEGIN { no warnings 'redefine'; @@ -49,11 +49,11 @@ sub new { my $dir = $args{dir}; if (defined $dir) { - $dir = abs_path $dir; + $dir = Cwd::abs_path($dir); } else { - $dir = cwd; + $dir = Cwd::cwd; } - $dir = canonpath $dir; + $dir = File::Spec->canonpath($dir); my ($repo, $bare, $name, $work); if ($args{fake}) { @@ -64,18 +64,18 @@ sub new { and -d "$dir/objects" and -e "$dir/HEAD"; - my @chunks = splitdir $dir; + my @chunks = File::Spec->splitdir($dir); my $last = pop @chunks; return unless defined $last; - if ($last eq '.git') { + if (@chunks and $last eq '.git') { $bare = 0; $name = $chunks[-1]; - $work = catdir @chunks; + $work = File::Spec->catdir(@chunks); } elsif ($last =~ /(.+)\.git$/) { $bare = 1; $name = $1; - $work = catdir @chunks, $last; + $work = File::Spec->catdir(@chunks, $last); } else { return; } @@ -116,22 +116,25 @@ Returns the exit code. =cut -sub _abs2rel { - my $a = &abs2rel; +my $abs2rel = sub { + my $a = File::Spec->abs2rel(@_); $a = $_[0] unless defined $a; $a; -} +}; my %escapes = ( '%' => sub { '%' }, 'n' => sub { shift->name }, - 'g' => sub { _abs2rel(shift->repo, shift->root) }, + 'g' => sub { $abs2rel->(shift->repo, shift->root) }, 'G' => sub { shift->repo }, - 'w' => sub { _abs2rel(shift->work, shift->root) }, + 'w' => sub { $abs2rel->(shift->work, shift->root) }, 'W' => sub { shift->work }, 'b' => sub { my ($self, $conf) = @_; - _abs2rel($self->bare ? $self->repo : $self->work . '.git', $conf->root) + $abs2rel->( + $self->bare ? $self->repo : $self->work . '.git', + $conf->root + ); }, 'B' => sub { $_[0]->bare ? $_[0]->repo : $_[0]->work . '.git' }, 'R' => sub { $_[1]->root }, @@ -143,21 +146,27 @@ sub run { my $self = shift; my $conf = shift; return unless $conf->isa('App::Rgit::Config'); + my @args = @_; + unless ($self->fake) { s/%($e)/$escapes{$1}->($self, $conf)/eg for @args; } + unshift @args, $conf->git; $conf->info('Executing "', join(' ', @args), '" into ', $self->work, "\n"); + { local $ENV{GIT_DIR} = $self->repo if exists $ENV{GIT_DIR}; local $ENV{GIT_EXEC_PATH} = $conf->git if exists $ENV{GIT_EXEC_PATH}; system { $args[0] } @args; } + if ($? == -1) { $conf->crit("Failed to execute git: $!\n"); return; } + my $ret; $ret = WEXITSTATUS($?) if WIFEXITED($?); my $sig; @@ -171,6 +180,7 @@ sub run { } elsif ($ret) { $conf->info("git returned $ret\n"); } + return wantarray ? ($ret, $sig) : $ret; } diff --git a/t/15-failures.t b/t/15-failures.t index d071188..7652989 100644 --- a/t/15-failures.t +++ b/t/15-failures.t @@ -3,8 +3,8 @@ use strict; use warnings; -use Cwd qw/cwd/; -use File::Spec::Functions qw/catdir/; +use Cwd (); # cwd +use File::Spec (); # catdir use Test::More tests => 42; @@ -173,8 +173,8 @@ is_deeply $res, [ ], '$arc->repos: cached ok'; use App::Rgit::Repository; -my $cwd = cwd; -my $t = catdir($cwd, 't'); +my $cwd = Cwd::cwd; +my $t = File::Spec->catdir($cwd, 't'); chdir $t or die "chdir($t): $!"; $res = eval { diff --git a/t/20-each.t b/t/20-each.t index a3a26e5..ed1c0c2 100644 --- a/t/20-each.t +++ b/t/20-each.t @@ -3,9 +3,9 @@ use strict; use warnings; -use Cwd qw/cwd abs_path/; -use File::Spec::Functions qw/catdir catfile/; -use File::Temp qw/tempfile tempdir/; +use Cwd qw/cwd abs_path/; +use File::Spec (); # catdir, catfile +use File::Temp qw/tempfile tempdir/; use Test::More; @@ -33,7 +33,7 @@ sub build { while (my ($d, $v) = each %$tree) { if (ref $v) { - my $dir = catdir($prefix, $d); + my $dir = File::Spec->catdir($prefix, $d); mkdir $dir or die "mkdir($dir): $!"; my @r = build($v, $dir); @@ -43,12 +43,12 @@ sub build { push @ret, [ $_->[0], ref eq 'main' ? @{$_}[1 .. 3] - : map catdir($d, $_), @{$_}[1 .. 3] + : map File::Spec->catdir($d, $_), @{$_}[1 .. 3] ]; } } } else { - my $file = catfile($prefix, $d); + my $file = File::Spec->catfile($prefix, $d); open my $fh, '>', $file or die "open($file): $!"; print $fh $v; close $fh; @@ -67,8 +67,8 @@ my $repogit = { sub repo { my ($n, $bare) = @_; - return $bare ? [ $n, "$n.git", "$n.git", "$n.git" ] - : [ $n, catdir($n, '.git'), $n, "$n.git" ] + return $bare ? [ $n, "$n.git", "$n.git", "$n.git" ] + : [ $n, File::Spec->catdir($n, '.git'), $n, "$n.git" ] } my $tmpdir = tempdir(CLEANUP => 1); @@ -113,7 +113,7 @@ is grep({ ref eq 'ARRAY' } @expected), 3, 'all of them are array references'; @expected = map [ @$_, - map(catdir($tmpdir, $_), @{$_}[1 .. 3]), + map(File::Spec->catdir($tmpdir, $_), @{$_}[1 .. 3]), $tmpdir, '%n', '%x' ], @expected; diff --git a/t/lib/App/Rgit/TestUtils.pm b/t/lib/App/Rgit/TestUtils.pm index de5b808..f702b25 100644 --- a/t/lib/App/Rgit/TestUtils.pm +++ b/t/lib/App/Rgit/TestUtils.pm @@ -3,10 +3,10 @@ package App::Rgit::TestUtils; use strict; use warnings; -use Cwd qw/abs_path/; -use File::Temp qw/tempfile/; -use File::Spec::Functions qw/curdir catfile/; -use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG/; +use Cwd qw/abs_path/; +use File::Temp qw/tempfile/; +use File::Spec (); # curdir, catfile +use POSIX qw/WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG/; BEGIN { no warnings 'redefine'; @@ -31,7 +31,7 @@ TRY: 'version', ); - my $git = catfile(curdir, qw/t bin git/); + my $git = File::Spec->catfile(File::Spec->curdir, qw/t bin git/); if ($^O eq 'MSWin32') { unless (-x $git) { $git .= '.bat';