line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Mapper; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
81256
|
$Path::Mapper::VERSION = '0.012'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Map a virtual path to an actual one |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
8
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
675
|
use Any::Moose; |
|
1
|
|
|
|
|
39030
|
|
|
1
|
|
|
|
|
8
|
|
12
|
1
|
|
|
1
|
|
1766
|
use Path::Abstract(); |
|
1
|
|
|
|
|
77301
|
|
|
1
|
|
|
|
|
21
|
|
13
|
1
|
|
|
1
|
|
9
|
use Path::Class(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
732
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has _map => qw/is ro isa HashRef required 1/, default => sub { {} }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BUILD { |
18
|
5
|
|
|
5
|
1
|
11
|
my $self = shift; |
19
|
5
|
|
|
|
|
7
|
my $given = shift; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
10
|
my $base = $given->{base}; |
22
|
5
|
50
|
|
|
|
14
|
$base = '' unless defined $base; |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
|
|
|
15
|
$self->map( '' => $base ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub base { |
29
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
30
|
0
|
0
|
|
|
|
0
|
if (@_) { |
31
|
0
|
|
|
|
|
0
|
$self->map( '' => shift ); |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
0
|
return $self->_map->{''}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub map { |
37
|
198
|
|
|
198
|
1
|
25009
|
my $self = shift; |
38
|
198
|
100
|
|
|
|
409
|
if (@_ == 2) { |
39
|
19
|
|
|
|
|
20
|
my $virtual = shift; |
40
|
19
|
|
|
|
|
18
|
my $actual = shift; |
41
|
|
|
|
|
|
|
|
42
|
19
|
50
|
|
|
|
52
|
$virtual = '' unless defined $virtual; # Undefined behavior, set the base path |
43
|
19
|
|
|
|
|
31
|
$virtual = "/$virtual"; # Normalize with leading slash |
44
|
19
|
|
|
|
|
78
|
$virtual =~ s/\/*$//; # Get rid of trailing slash(es) |
45
|
19
|
|
|
|
|
66
|
$virtual = Path::Abstract->new( $virtual ); |
46
|
19
|
50
|
|
|
|
536
|
$virtual = Path::Abstract->new( '' ) if $virtual->is_root; |
47
|
|
|
|
|
|
|
|
48
|
19
|
50
|
|
|
|
105
|
if (defined $actual) { |
49
|
19
|
50
|
|
|
|
81
|
$actual = Path::Abstract->new( $actual.'' ) if defined $actual; |
50
|
19
|
|
|
|
|
467
|
$self->_map->{$virtual.''} = $actual; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
0
|
delete $self->_map->{$virtual.''}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
179
|
|
|
|
|
215
|
my $query = shift; |
58
|
179
|
50
|
|
|
|
408
|
$query = '' unless defined $query; # Undefined behavior |
59
|
|
|
|
|
|
|
|
60
|
179
|
|
|
|
|
782
|
$query = Path::Abstract->new( "/$query" ); # Normalize with leading slash |
61
|
179
|
|
|
|
|
5839
|
my $query_ = $query.''; |
62
|
179
|
|
|
|
|
711
|
study $query_; |
63
|
|
|
|
|
|
|
|
64
|
179
|
|
|
|
|
193
|
my $found = ''; |
65
|
179
|
|
|
|
|
175
|
for my $virtual (keys %{ $self->_map }) { |
|
179
|
|
|
|
|
738
|
|
66
|
707
|
100
|
|
|
|
10355
|
if ($query =~ m/^$virtual(?:\/|$)/) { |
67
|
355
|
100
|
|
|
|
2764
|
if (length $virtual > length $found) { |
68
|
112
|
|
|
|
|
283
|
$found = $virtual; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
179
|
|
|
|
|
1047
|
my $base = $self->_map->{$found}; |
74
|
179
|
|
|
|
|
406
|
my $remainder = substr $query, length $found; |
75
|
179
|
100
|
|
|
|
1001
|
substr $remainder, 0, 1, '' if 0 == index $remainder, '/'; |
76
|
|
|
|
|
|
|
|
77
|
179
|
|
|
|
|
466
|
my @result = ($base.'', $remainder); |
78
|
179
|
100
|
|
|
|
1488
|
return wantarray ? @result : \@result; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub dir { |
83
|
44
|
|
|
44
|
1
|
29431
|
my $self = shift; |
84
|
44
|
|
|
|
|
94
|
my ($base, $remainder) = $self->map( shift ); |
85
|
44
|
|
|
|
|
66
|
return Path::Class::Dir->new( grep { length $_ } $base, $remainder ); |
|
88
|
|
|
|
|
237
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub file { |
89
|
44
|
|
|
44
|
1
|
54
|
my $self = shift; |
90
|
44
|
|
|
|
|
90
|
my ($base, $remainder) = $self->map( shift ); |
91
|
44
|
|
|
|
|
84
|
return Path::Class::File->new( grep { length $_ } $base, $remainder ); |
|
88
|
|
|
|
|
268
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub path { |
95
|
47
|
|
|
47
|
1
|
32682
|
my $self = shift; |
96
|
47
|
|
|
|
|
102
|
my ($base, $remainder) = $self->map( shift ); |
97
|
47
|
|
|
|
|
85
|
return Path::Abstract->new( grep { length $_ } $base, $remainder ); |
|
94
|
|
|
|
|
3097
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
__END__ |