1 package ExtUtils::Command;
9 use File::Path qw(rmtree);
11 use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
13 @EXPORT = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f chmod
17 my $Is_VMS = $^O eq 'VMS';
21 ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
25 perl -MExtUtils::Command -e cat files... > destination
26 perl -MExtUtils::Command -e mv source... destination
27 perl -MExtUtils::Command -e cp source... destination
28 perl -MExtUtils::Command -e touch files...
29 perl -MExtUtils::Command -e rm_f files...
30 perl -MExtUtils::Command -e rm_rf directories...
31 perl -MExtUtils::Command -e mkpath directories...
32 perl -MExtUtils::Command -e eqtime source destination
33 perl -MExtUtils::Command -e test_f file
34 perl -MExtUtils::Command -e chmod mode files...
39 The module is used to replace common UNIX commands. In all cases the
40 functions work from @ARGV rather than taking arguments. This makes
41 them easier to deal with in Makefiles.
43 perl -MExtUtils::Command -e some_command some files to work on
47 perl -MExtUtils::Command -e 'some_command qw(some files to work on)'
49 Filenames with * and ? will be glob expanded.
55 # VMS uses % instead of ? to mean "one character"
56 my $wild_regex = $Is_VMS ? '*%' : '*?';
59 @ARGV = map(/[$wild_regex]/o ? glob($_) : $_,@ARGV);
65 Concatenates all files mentioned on command line to STDOUT.
77 Sets modified time of dst to that of src
83 my ($src,$dst) = @ARGV;
84 local @ARGV = ($dst); touch(); # in case $dst doesn't exist
85 utime((stat($src))[8,9],$dst);
90 Removes directories - recursively (even if readonly)
97 rmtree([grep -e $_,@ARGV],0,0);
102 Removes files (even if readonly)
115 carp "Cannot delete $_:$!";
119 =item touch files ...
121 Makes files exist, with current timestamp
128 foreach my $file (@ARGV) {
129 open(FILE,">>$file") || die "Cannot write $file:$!";
135 =item mv source... destination
137 Moves source to destination. Multiple sources are allowed if
138 destination is an existing directory.
140 Returns true if all moves succeeded, false otherwise.
149 croak("Too many arguments") if (@src > 1 && ! -d $dst);
152 foreach my $src (@src) {
153 $nok ||= !move($src,$dst);
158 =item cp source... destination
160 Copies source to destination. Multiple sources are allowed if
161 destination is an existing directory.
163 Returns true if all copies succeeded, false otherwise.
172 croak("Too many arguments") if (@src > 1 && ! -d $dst);
175 foreach my $src (@src) {
176 $nok ||= !copy($src,$dst);
181 =item chmod mode files...
183 Sets UNIX like permissions 'mode' on all the files. e.g. 0666
189 my $mode = shift(@ARGV);
191 chmod(oct $mode,@ARGV) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
194 =item mkpath directory...
196 Creates directory, including any parent directories.
203 File::Path::mkpath([@ARGV],0,0777);
208 Tests if a file exists
219 Converts DOS and OS/2 linefeeds to Unix style recursively.
225 File::Find::find(sub {
234 my $temp = '.dos2unix_tmp';
235 open ORIG, $_ or do { warn "dos2unix can't open $_: $!"; return };
236 open TEMP, ">$temp" or
237 do { warn "dos2unix can't create .dos2unix_tmp: $!"; return };
238 while (my $line = <ORIG>) {
239 $line =~ s/\015\012/\012/g;
253 Should probably be Auto/Self loaded.
257 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
261 Nick Ing-Simmons C<ni-s@cpan.org>
263 Currently maintained by Michael G Schwern C<schwern@pobox.com>.