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 file...
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 chmod mode files...
33 perl -MExtUtils::Command -e test_f file
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);
62 Concatenates all files mentioned on command line to STDOUT.
74 Sets modified time of dst to that of src
80 my ($src,$dst) = @ARGV;
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
129 my $file = shift(@ARGV);
130 open(FILE,">>$file") || die "Cannot write $file:$!";
136 =item mv source... destination
138 Moves source to destination.
139 Multiple sources are allowed if destination is an existing directory.
145 my $dst = pop(@ARGV);
147 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
150 my $src = shift(@ARGV);
155 =item cp source... destination
157 Copies source to destination.
158 Multiple sources are allowed if destination is an existing directory.
164 my $dst = pop(@ARGV);
166 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
169 my $src = shift(@ARGV);
174 =item chmod mode files...
176 Sets UNIX like permissions 'mode' on all the files.
182 my $mode = shift(@ARGV);
184 chmod($mode,@ARGV) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
187 =item mkpath directory...
189 Creates directory, including any parent directories.
196 File::Path::mkpath([@ARGV],0,0777);
201 Tests if a file exists
207 exit !-f shift(@ARGV);
218 Should probably be Auto/Self loaded.
222 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
226 Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.