1 package ExtUtils::Command;
9 use File::Path qw(rmtree);
11 use vars qw(@ISA @EXPORT $VERSION);
13 @EXPORT = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f);
18 ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
22 perl -MExtUtils::Command -e cat files... > destination
23 perl -MExtUtils::Command -e mv source... destination
24 perl -MExtUtils::Command -e cp source... destination
25 perl -MExtUtils::Command -e touch files...
26 perl -MExtUtils::Command -e rm_f file...
27 perl -MExtUtils::Command -e rm_rf directories...
28 perl -MExtUtils::Command -e mkpath directories...
29 perl -MExtUtils::Command -e eqtime source destination
30 perl -MExtUtils::Command -e chmod mode files...
31 perl -MExtUtils::Command -e test_f file
35 The module is used to replace common UNIX commands. In all cases the
36 functions work from @ARGV rather than taking arguments. This makes
37 them easier to deal with in Makefiles.
39 perl -MExtUtils::Command -e some_command some files to work on
43 perl -MExtUtils::Command -e 'some_command qw(some files to work on)'
45 Filenames with * and ? will be glob expanded.
53 @ARGV = map(/[\*\?]/ ? glob($_) : $_,@ARGV);
58 Concatenates all files mentioned on command line to STDOUT.
70 Sets modified time of dst to that of src
76 my ($src,$dst) = @ARGV;
79 utime((stat($src))[8,9],$dst);
84 Removes directories - recursively (even if readonly)
91 rmtree([grep -e $_,@ARGV],0,0);
96 Removes files (even if readonly)
109 carp "Cannot delete $_:$!";
113 =item touch files ...
115 Makes files exist, with current timestamp
125 my $file = shift(@ARGV);
126 open(FILE,">>$file") || die "Cannot write $file:$!";
132 =item mv source... destination
134 Moves source to destination.
135 Multiple sources are allowed if destination is an existing directory.
141 my $dst = pop(@ARGV);
143 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
146 my $src = shift(@ARGV);
151 =item cp source... destination
153 Copies source to destination.
154 Multiple sources are allowed if destination is an existing directory.
160 my $dst = pop(@ARGV);
162 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
165 my $src = shift(@ARGV);
170 =item chmod mode files...
172 Sets UNIX like permissions 'mode' on all the files.
178 my $mode = shift(@ARGV);
180 chmod($mode,@ARGV) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
183 =item mkpath directory...
185 Creates directory, including any parent directories.
192 File::Path::mkpath([@ARGV],0,0777);
197 Tests if a file exists
203 exit !-f shift(@ARGV);
214 Should probably be Auto/Self loaded.
218 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
222 Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.