line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Canonical; |
2
|
3
|
|
|
3
|
|
43207
|
use 5.008005; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
593
|
|
3
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
94
|
|
4
|
3
|
|
|
3
|
|
22
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
81
|
|
5
|
3
|
|
|
3
|
|
19
|
use base 'Exporter'; |
|
3
|
|
|
|
|
17
|
|
|
3
|
|
|
|
|
1313
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw/canon_path canon_filepath/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub canon_filepath { |
12
|
0
|
|
|
0
|
0
|
0
|
my $path = shift; |
13
|
0
|
0
|
|
|
|
0
|
return canon_path($path) if $^O ne 'MSWin32'; |
14
|
0
|
|
|
|
|
0
|
$path =~ s!\\!/!g; |
15
|
0
|
|
|
|
|
0
|
$path =~ s!^([a-zA-Z]:|//[^/]+/+[^/]+)!!g; |
16
|
0
|
|
0
|
|
|
0
|
$path = ($&||'') . canon_path($path); |
17
|
0
|
|
|
|
|
0
|
$path =~ s!/!\\!g; |
18
|
0
|
|
|
|
|
0
|
$path; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub canon_path { |
22
|
16
|
|
|
16
|
0
|
38
|
my $path = shift; |
23
|
16
|
|
|
|
|
26
|
my @ret = (); |
24
|
16
|
100
|
|
|
|
66
|
$path .= '/' if $path =~ /[.\/]$/; |
25
|
16
|
|
|
|
|
105
|
for my $tok (split(/\/+/, $path . '-')) { |
26
|
88
|
100
|
|
|
|
156
|
next if $tok eq '.'; |
27
|
72
|
100
|
|
|
|
126
|
if ($tok eq '..') { |
28
|
21
|
|
|
|
|
25
|
pop @ret; |
29
|
21
|
|
|
|
|
31
|
next; |
30
|
|
|
|
|
|
|
} |
31
|
51
|
100
|
|
|
|
126
|
push @ret, $tok if $tok; |
32
|
|
|
|
|
|
|
} |
33
|
16
|
|
|
|
|
100
|
'/' . substr(join('/', @ret), 0, -1) |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |