1 package ExtUtils::Command;
10 use File::Path qw(rmtree);
12 our(@ISA, @EXPORT, $VERSION);
14 @EXPORT = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f);
19 ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
23 perl -MExtUtils::Command -e cat files... > destination
24 perl -MExtUtils::Command -e mv source... destination
25 perl -MExtUtils::Command -e cp source... destination
26 perl -MExtUtils::Command -e touch files...
27 perl -MExtUtils::Command -e rm_f file...
28 perl -MExtUtils::Command -e rm_rf directories...
29 perl -MExtUtils::Command -e mkpath directories...
30 perl -MExtUtils::Command -e eqtime source destination
31 perl -MExtUtils::Command -e chmod mode files...
32 perl -MExtUtils::Command -e test_f file
36 The module is used to replace common UNIX commands.
44 @ARGV = map(/[\*\?]/ ? glob($_) : $_,@ARGV);
49 Concatenates all files mentioned on command line to STDOUT.
61 Sets modified time of dst to that of src
67 my ($src,$dst) = @ARGV;
70 utime((stat($src))[8,9],$dst);
75 Removes directories - recursively (even if readonly)
81 rmtree([grep -e $_,expand_wildcards()],0,0);
86 Removes files (even if readonly)
92 foreach (expand_wildcards())
98 carp "Cannot delete $_:$!";
102 =item touch files ...
104 Makes files exist, with current timestamp
114 my $file = shift(@ARGV);
115 open(FILE,">>$file") || die "Cannot write $file:$!";
121 =item mv source... destination
123 Moves source to destination.
124 Multiple sources are allowed if destination is an existing directory.
130 my $dst = pop(@ARGV);
132 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
135 my $src = shift(@ARGV);
140 =item cp source... destination
142 Copies source to destination.
143 Multiple sources are allowed if destination is an existing directory.
149 my $dst = pop(@ARGV);
151 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
154 my $src = shift(@ARGV);
159 =item chmod mode files...
161 Sets UNIX like permissions 'mode' on all the files.
167 my $mode = shift(@ARGV);
168 chmod($mode,expand_wildcards()) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
171 =item mkpath directory...
173 Creates directory, including any parent directories.
179 File::Path::mkpath([expand_wildcards()],0,0777);
184 Tests if a file exists
190 exit !-f shift(@ARGV);
201 Should probably be Auto/Self loaded.
205 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
209 Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.