| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Path::Trim; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
649550
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
75
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
69
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2861
|
use version; our $VERSION = qv('0.0.3'); |
|
|
2
|
|
|
|
|
7992
|
|
|
|
2
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
|
9
|
1
|
|
|
1
|
1
|
15
|
return bless {}, __PACKAGE__; |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_current_directory { |
|
13
|
130
|
|
|
130
|
1
|
185
|
my $self = shift; |
|
14
|
130
|
|
100
|
|
|
504
|
return $self->{'current_directory'} || '.'; |
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub set_current_directory { |
|
18
|
2
|
|
|
2
|
1
|
5
|
my ( $self, $current_directory ) = @_; |
|
19
|
2
|
|
|
|
|
11
|
return $self->{'current_directory'} = $current_directory; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub get_parent_directory { |
|
23
|
130
|
|
|
130
|
1
|
165
|
my $self = shift; |
|
24
|
130
|
|
100
|
|
|
387
|
return $self->{'parent_directory'} || '..'; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub set_parent_directory { |
|
28
|
2
|
|
|
2
|
1
|
5
|
my ( $self, $parent_directory ) = @_; |
|
29
|
2
|
|
|
|
|
12
|
return $self->{'parent_directory'} = $parent_directory; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub get_directory_separator { |
|
33
|
128
|
|
|
128
|
1
|
156
|
my $self = shift; |
|
34
|
128
|
|
|
|
|
227
|
return $self->{'directory_separator'}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub set_directory_separator { |
|
38
|
2
|
|
|
2
|
1
|
9
|
my ( $self, $directory_separator ) = @_; |
|
39
|
2
|
|
|
|
|
12
|
return $self->{'directory_separator'} = $directory_separator; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub trim_path { |
|
43
|
128
|
|
|
128
|
1
|
268
|
my ( $self, $path ) = @_; |
|
44
|
128
|
|
|
|
|
264
|
my $current_directory = $self->get_current_directory(); |
|
45
|
128
|
|
|
|
|
324
|
my $parent_directory = $self->get_parent_directory(); |
|
46
|
128
|
|
|
|
|
292
|
my $directory_separator = $self->get_directory_separator(); |
|
47
|
128
|
|
|
|
|
163
|
my ( $left_stripped, $right_stripped ); |
|
48
|
128
|
100
|
|
|
|
742
|
if ( $path =~ s/^\Q$directory_separator\E// ) { |
|
49
|
64
|
|
|
|
|
101
|
$left_stripped = 1; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
128
|
100
|
|
|
|
555
|
if ( $path =~ s/\Q$directory_separator\E$// ) { |
|
52
|
64
|
|
|
|
|
98
|
$right_stripped = 1; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
128
|
|
|
|
|
568
|
my @dirs = split /\Q$directory_separator\E/, $path; |
|
55
|
128
|
|
|
|
|
176
|
my @new_path; |
|
56
|
|
|
|
|
|
|
|
|
57
|
128
|
|
|
|
|
211
|
for my $dir (@dirs) { |
|
58
|
400
|
100
|
|
|
|
1024
|
if ( $dir eq $parent_directory ) { |
|
|
|
100
|
|
|
|
|
|
|
59
|
160
|
100
|
100
|
|
|
608
|
if ( @new_path && $new_path[-1] ne $parent_directory ) { |
|
60
|
40
|
|
|
|
|
98
|
pop @new_path; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
120
|
|
|
|
|
261
|
push @new_path, $parent_directory; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
elsif ( $dir ne $current_directory ) { |
|
67
|
112
|
|
|
|
|
250
|
push @new_path, $dir; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
128
|
100
|
|
|
|
296
|
if ( !@new_path ) { |
|
72
|
16
|
|
|
|
|
22
|
push @new_path, $current_directory; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
128
|
|
|
|
|
229
|
my $new_path = join $directory_separator, @new_path; |
|
76
|
128
|
100
|
|
|
|
237
|
if ($left_stripped) { |
|
77
|
64
|
|
|
|
|
172
|
$new_path = $directory_separator . $new_path; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
128
|
100
|
|
|
|
250
|
if ($right_stripped) { |
|
80
|
64
|
|
|
|
|
82
|
$new_path = $new_path . $directory_separator; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
128
|
|
|
|
|
1304
|
return $new_path; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
|
86
|
|
|
|
|
|
|
__END__ |