/
Cygwin.pm
50 lines (40 loc) · 1.71 KB
/
Cygwin.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
my class IO::Spec::Cygwin is IO::Spec::Unix {
#| Any C<\> (backslashes) are converted to C</> (forward slashes),
#| and then IO::Spec::Unix.canonpath() is called on the result.
method canonpath (Cool:D $path is copy) {
$path.=subst(:g, '\\', '/');
# Handle network path names beginning with double slash
my $node = '';
if $path ~~ s/^ ('//' <-[/]>+) [ '/' | $ ] /\// { #/
$node = ~$0;
}
$node ~ IO::Spec::Unix.canonpath($path);
}
#| Calls the Unix version, and additionally prevents
#| accidentally creating a //network/path.
method catdir ( *@paths ) {
my $result = IO::Spec::Unix.catdir(@paths);
# Don't create something that looks like a //network/path
$result.subst(/ <[\\\/]> ** 2..*/, '/');
}
#| Tests if the file name begins with C<drive_letter:/> or a slash.
method is-absolute ($file) {
so $file ~~ / ^ [<[A..Z a..z]> ':']? <[\\/]>/; # C:/test
}
method tmpdir {
self.canonpath: first( { .defined && .IO.d && .IO.w },
%*ENV<TMPDIR>,
"/tmp",
%*ENV<TMP>,
%*ENV<TEMP>,
'C:/temp')
|| self.curdir;
}
# Paths might have a volume, so we use Win32 splitpath and catpath instead
method splitpath (|c) { IO::Spec::Win32.splitpath(|c) }
method catpath (|c) { IO::Spec::Win32.catpath(|c).subst(:global, '\\', '/') }
method split ($path) { IO::Spec::Win32.split($path).map:
{ (.key => .value.subst(:global, '\\', '/')) } }
method join (|c) { IO::Spec::Win32.join(|c).subst(:global, '\\', '/') }
}
# vim: ft=perl6 expandtab sw=4