line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Naive; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
505
|
use 5.010001; |
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.040'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
728
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
split_path |
13
|
|
|
|
|
|
|
normalize_path |
14
|
|
|
|
|
|
|
is_abs_path |
15
|
|
|
|
|
|
|
is_rel_path |
16
|
|
|
|
|
|
|
concat_path |
17
|
|
|
|
|
|
|
concat_path_n |
18
|
|
|
|
|
|
|
abs_path |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub split_path { |
22
|
57
|
100
|
100
|
57
|
1
|
2495
|
die "Please specify path" unless defined($_[0]) && length($_[0]); |
23
|
51
|
|
|
|
|
478
|
grep {length} split qr!/+!, $_[0]; |
|
136
|
|
|
|
|
340
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub normalize_path { |
27
|
44
|
|
|
44
|
1
|
3991
|
my @d0 = split_path $_[0]; |
28
|
41
|
|
|
|
|
111
|
my $abs = $_[0] =~ m!\A/!; |
29
|
41
|
|
|
|
|
53
|
my @d; |
30
|
41
|
|
|
|
|
86
|
while (@d0) { |
31
|
101
|
|
|
|
|
148
|
my $d = shift @d0; |
32
|
101
|
100
|
100
|
|
|
259
|
next if $d eq '.' && (@d || @d0 || $abs); |
|
|
|
100
|
|
|
|
|
33
|
82
|
100
|
100
|
|
|
248
|
do { pop @d; next } if $d eq '..' && |
|
13
|
|
100
|
|
|
20
|
|
|
13
|
|
|
|
|
32
|
|
34
|
|
|
|
|
|
|
(@d>1 && $d[-1] ne '..' || |
35
|
|
|
|
|
|
|
@d==1 && $d[-1] ne '..' && $d[-1] ne '.' && @d0 || |
36
|
|
|
|
|
|
|
$abs); |
37
|
69
|
|
|
|
|
152
|
push @d, $d; |
38
|
|
|
|
|
|
|
} |
39
|
41
|
100
|
|
|
|
78
|
if (wantarray) { |
40
|
3
|
|
|
|
|
21
|
@d; |
41
|
|
|
|
|
|
|
} else { |
42
|
38
|
100
|
|
|
|
215
|
($abs ? "/" : "") . join("/", @d); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub is_abs_path { |
47
|
15
|
100
|
100
|
15
|
1
|
3654
|
die "Please specify path" unless defined($_[0]) && length($_[0]); |
48
|
12
|
100
|
|
|
|
70
|
$_[0] =~ m!\A/! ? 1:0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_rel_path { |
52
|
5
|
100
|
100
|
5
|
1
|
3689
|
die "Please specify path" unless defined($_[0]) && length($_[0]); |
53
|
2
|
100
|
|
|
|
13
|
$_[0] =~ m!\A/! ? 0:1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub concat_path { |
57
|
29
|
100
|
|
29
|
1
|
3638
|
die "Please specify at least two paths" unless @_ > 1; |
58
|
23
|
|
|
|
|
35
|
my $i = 0; |
59
|
23
|
|
|
|
|
37
|
my $res = $_[0]; |
60
|
23
|
|
|
|
|
42
|
for (@_) { |
61
|
49
|
50
|
33
|
|
|
145
|
die "Please specify path (#$i)" unless defined && length; |
62
|
49
|
100
|
|
|
|
98
|
next unless $i++; |
63
|
26
|
100
|
|
|
|
73
|
if (m!\A/!) { |
64
|
7
|
|
|
|
|
12
|
$res = $_; |
65
|
|
|
|
|
|
|
} else { |
66
|
19
|
100
|
|
|
|
73
|
$res .= ($res =~ m!/\z! ? "" : "/") . $_; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
23
|
|
|
|
|
63
|
$res; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub concat_path_n { |
73
|
18
|
|
|
18
|
1
|
3577
|
normalize_path(concat_path(@_)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub abs_path { |
77
|
9
|
100
|
100
|
9
|
1
|
4065
|
die "Please specify path" unless defined($_[0]) && length($_[0]); |
78
|
6
|
50
|
33
|
|
|
23
|
die "Please specify base" unless defined($_[1]) && length($_[1]); |
79
|
6
|
100
|
|
|
|
15
|
die "base must be absolute" unless is_abs_path($_[1]); |
80
|
5
|
|
|
|
|
13
|
concat_path_n($_[1], $_[0]); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
# ABSTRACT: Yet another abstract, Unix-like path manipulation routines |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |