Merge branch 'master' of http://repo.or.cz/r/msysgit into devel
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / ExtUtils / Command.pm
blobaec4013d022ab5af779ad8bf05fab06a80fde4cb
1 package ExtUtils::Command;
3 use 5.005_64;
4 use strict;
5 # use AutoLoader;
6 use Carp;
7 use File::Copy;
8 use File::Compare;
9 use File::Basename;
10 use File::Path qw(rmtree);
11 require Exporter;
12 our(@ISA, @EXPORT, $VERSION);
13 @ISA = qw(Exporter);
14 @EXPORT = qw(cp rm_f rm_rf mv cat eqtime mkpath touch test_f);
15 $VERSION = '1.01';
17 =head1 NAME
19 ExtUtils::Command - utilities to replace common UNIX commands in Makefiles etc.
21 =head1 SYNOPSIS
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
34 =head1 DESCRIPTION
36 The module is used in the Win32 port to replace common UNIX commands.
37 Most commands are wrappers on generic modules File::Path and File::Basename.
39 =over 4
41 =cut
43 sub expand_wildcards
45 @ARGV = map(/[\*\?]/ ? glob($_) : $_,@ARGV);
48 =item cat
50 Concatenates all files mentioned on command line to STDOUT.
52 =cut
54 sub cat ()
56 expand_wildcards();
57 print while (<>);
60 =item eqtime src dst
62 Sets modified time of dst to that of src
64 =cut
66 sub eqtime
68 my ($src,$dst) = @ARGV;
69 open(F,">$dst");
70 close(F);
71 utime((stat($src))[8,9],$dst);
74 =item rm_f files....
76 Removes directories - recursively (even if readonly)
78 =cut
80 sub rm_rf
82 rmtree([grep -e $_,expand_wildcards()],0,0);
85 =item rm_f files....
87 Removes files (even if readonly)
89 =cut
91 sub rm_f
93 foreach (expand_wildcards())
95 next unless -f $_;
96 next if unlink($_);
97 chmod(0777,$_);
98 next if unlink($_);
99 carp "Cannot delete $_:$!";
103 =item touch files ...
105 Makes files exist, with current timestamp
107 =cut
109 sub touch
111 expand_wildcards();
112 my $t = time;
113 while (@ARGV)
115 my $file = shift(@ARGV);
116 open(FILE,">>$file") || die "Cannot write $file:$!";
117 close(FILE);
118 utime($t,$t,$file);
122 =item mv source... destination
124 Moves source to destination.
125 Multiple sources are allowed if destination is an existing directory.
127 =cut
129 sub mv
131 my $dst = pop(@ARGV);
132 expand_wildcards();
133 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
134 while (@ARGV)
136 my $src = shift(@ARGV);
137 move($src,$dst);
141 =item cp source... destination
143 Copies source to destination.
144 Multiple sources are allowed if destination is an existing directory.
146 =cut
148 sub cp
150 my $dst = pop(@ARGV);
151 expand_wildcards();
152 croak("Too many arguments") if (@ARGV > 1 && ! -d $dst);
153 while (@ARGV)
155 my $src = shift(@ARGV);
156 copy($src,$dst);
160 =item chmod mode files...
162 Sets UNIX like permissions 'mode' on all the files.
164 =cut
166 sub chmod
168 my $mode = shift(@ARGV);
169 chmod($mode,expand_wildcards()) || die "Cannot chmod ".join(' ',$mode,@ARGV).":$!";
172 =item mkpath directory...
174 Creates directory, including any parent directories.
176 =cut
178 sub mkpath
180 File::Path::mkpath([expand_wildcards()],0,0777);
183 =item test_f file
185 Tests if a file exists
187 =cut
189 sub test_f
191 exit !-f shift(@ARGV);
196 __END__
198 =back
200 =head1 BUGS
202 Should probably be Auto/Self loaded.
204 =head1 SEE ALSO
206 ExtUtils::MakeMaker, ExtUtils::MM_Unix, ExtUtils::MM_Win32
208 =head1 AUTHOR
210 Nick Ing-Simmons <F<nick@ni-s.u-net.com>>.
212 =cut