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);
16 my $Is_VMS = $^O eq 'VMS';
20 ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
24 perl -MExtUtils::Command -e cat files... > destination
25 perl -MExtUtils::Command -e mv source... destination
26 perl -MExtUtils::Command -e cp source... destination
27 perl -MExtUtils::Command -e touch files...
28 perl -MExtUtils::Command -e rm_f files...
29 perl -MExtUtils::Command -e rm_rf directories...
30 perl -MExtUtils::Command -e mkpath directories...
31 perl -MExtUtils::Command -e eqtime source destination
32 perl -MExtUtils::Command -e test_f file
33 perl -MExtUtils::Command=chmod -e chmod mode files...
37 The module is used to replace common UNIX commands. In all cases the
38 functions work from @ARGV rather than taking arguments. This makes
39 them easier to deal with in Makefiles.
41 perl -MExtUtils::Command -e some_command some files to work on
45 perl -MExtUtils::Command -e 'some_command qw(some files to work on)'
47 Filenames with * and ? will be glob expanded.
53 # VMS uses % instead of ? to mean "one character"
54 my $wild_regex = $Is_VMS ? '*%' : '*?';
57 @ARGV = map(/[$wild_regex]/o ? glob($_) : $_,@ARGV);
63 Concatenates all files mentioned on command line to STDOUT.
75 Sets modified time of dst to that of src
81 my ($src,$dst) = @ARGV;
82 local @ARGV = ($dst); touch(); # in case $dst doesn't exist
83 utime((stat($src))[8,9],$dst);
88 Removes directories - recursively (even if readonly)
95 rmtree([grep -e $_,@ARGV],0,0);
100 Removes files (even if readonly)
113 carp "Cannot delete $_:$!";
117 =item touch files ...
119 Makes files exist, with current timestamp
126 foreach my $file (@ARGV) {
127 open(FILE,">>$file") || die "Cannot write $file:$!";
133 =item mv source... destination
135 Moves source to destination.
136 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);
144 foreach my $src (@ARGV) {
149 =item cp source... destination
151 Copies source to destination.
152 Multiple sources are allowed if destination is an existing directory.
157 my $dst = pop(@ARGV);
159 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
160 foreach my $src (@ARGV) {
165 =item chmod mode files...
167 Sets UNIX like permissions 'mode' on all the files. e.g. 0666
172 my $mode = shift(@ARGV);
174 chmod(oct $mode,@ARGV) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
177 =item mkpath directory...
179 Creates directory, including any parent directories.
186 File::Path::mkpath([@ARGV],0,0777);
191 Tests if a file exists
197 exit !-f shift(@ARGV);
208 Should probably be Auto/Self loaded.
212 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
216 Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.