Doit
view release on metacpan or search on metacpan
lib/Doit.pm view on Meta::CPAN
push @print_cmd, $arg;
}
}
join " ", @print_cmd;
},
rv => 1,
};
Doit::Commands->new(@commands);
}
sub cmd_setenv {
my($self, $key, $val) = @_;
if (!defined $ENV{$key} || $ENV{$key} ne $val) {
my @commands = {
code => sub { $ENV{$key} = $val },
msg => qq{set \$ENV{$key} to "$val", previous value was } . (defined $ENV{$key} ? qq{"$ENV{$key}"} : qq{unset}),
rv => 1,
};
Doit::Commands->new(@commands);
} else {
Doit::Commands->return_zero;
lib/Doit.pm view on Meta::CPAN
my @commands = {
code => sub { unlink @files_to_remove or error "$!" },
msg => "unlink @files_to_remove", # shellquote?
};
Doit::Commands->new(@commands);
} else {
Doit::Commands->return_zero;
}
}
sub cmd_unsetenv {
my($self, $key) = @_;
if (defined $ENV{$key}) {
my @commands = {
code => sub { delete $ENV{$key} },
msg => qq{unset \$ENV{$key}, previous value was "$ENV{$key}"},
rv => 1,
};
Doit::Commands->new(@commands);
} else {
Doit::Commands->return_zero;
lib/Doit.pm view on Meta::CPAN
qw(open2 info_open2), # IPC::Open2
qw(open3 info_open3), # IPC::Open3
qw(system info_system), # builtin system with variant
qw(cond_run), # conditional run
qw(touch), # like unix touch
qw(ln_nsf), # like unix ln -nsf
qw(which), # like unix which
qw(create_file_if_nonexisting), # does the half of touch
qw(write_binary), # like File::Slurper
qw(change_file), # own invention
qw(setenv unsetenv), # $ENV manipulation
) {
__PACKAGE__->install_cmd($cmd);
}
sub call_wrapped_method {
my($self, $context, $method, @args) = @_;
my @ret;
if ($context eq 'a') {
@ret = eval { $self->$method(@args) };
} else {
lib/Doit.pod view on Meta::CPAN
Always returns C<1> (unless there's an exception).
=head3 rmdir
$doit->rmdir($directory);
Make sure that the given I<$directory> is removed. Fails if this
directory is not empty. See L<perlfunc/rmdir> for details.
=head3 setenv
$doit->setenv($key, $val);
Make sure that I<%ENV> contains a key I<$key> set to I<$value>.
=head3 symlink
$doit->symlink($oldfile, $newfile);
Make sure that I<$newfile> is a symlink pointing to I<$oldfile>.
Contrary to L</ln_nsf> it does not change an existing symlink. See
L<perlfunc/symlink> for more details.
lib/Doit.pod view on Meta::CPAN
L</create_file_if_nonexisting>.
Always returns the number of given files (unless there's an exception).
=head3 unlink
$doit->unlink($file ...);
Make sure that the given files are deleted. See L<perlfunc/unlink>.
=head3 unsetenv
$doit->unsetenv($key);
Make sure that I<%ENV> does not contain the key I<$key> anymore.
=head3 utime
$doit->utime($atime, $mtime, $file ...);
Make sure that access time and modification time of the listed files
is set to the given values. Undefined time values are replaced by
current time. Fails if not all files could be changed. See
| EXTERNAL_DIFF
| MERGE_VERBOSITY
| SSH
| ASKPASS
| CONFIG_NOSYSTEM
| FLUSH
| TRACE.*
| .*_PATHSPECS
| REFLOG_ACTION
)$}x;
$d->unsetenv($git_key);
}
# realpath() needed on darwin (/private/tmp vs. /tmp)
my $dir = realpath(tempdir('doit-git-XXXXXXXX', CLEANUP => 1, TMPDIR => 1));
# A private git-short-status script; should behave the same as the git_short_status command.
my $my_git_short_status;
if ($ENV{HOME} && -x "$ENV{HOME}/bin/sh/git-short-status") {
$my_git_short_status = "$ENV{HOME}/bin/sh/git-short-status";
}
use Doit;
use Test::More;
plan 'no_plan';
my $doit = Doit->init;
{
local $ENV{TEST_SETENV} = 1;
is $doit->setenv(TEST_SETENV => 2), 1;
is $ENV{TEST_SETENV}, 2, 'value was changed (previously had other value)';
is $doit->setenv(TEST_SETENV => 2), 0;
is $ENV{TEST_SETENV}, 2, 'value was not changed';
$doit->unsetenv('TEST_SETENV'), 1;
ok !exists $ENV{TEST_SETENV}, 'value was deleted';
$doit->unsetenv('TEST_SETENV'), 0; # noop
}
{
local $ENV{TEST_SETENV};
is $doit->setenv(TEST_SETENV => 1), 1;
is $ENV{TEST_SETENV}, 1, 'value was changed (from previously non-existent)';
}
__END__
( run in 0.779 second using v1.01-cache-2.11-cpan-3989ada0592 )