line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Path::Role::Relative; |
2
|
1
|
|
|
1
|
|
693
|
use Mojo::Base -role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
1
|
|
|
1
|
|
980
|
use Mojo::File; |
|
1
|
|
|
|
|
29669
|
|
|
1
|
|
|
|
|
432
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# https://github.com/mojolicious/mojo/issues/573 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw{clone leading_slash new parts to_string trailing_slash}; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub is_subpath_of { |
12
|
6
|
|
|
6
|
1
|
565
|
my ($self, $base) = @_; |
13
|
6
|
100
|
|
|
|
17
|
$base = $self->new($base) unless ref($base); |
14
|
6
|
50
|
|
|
|
25
|
return 0 if @$base > @$self; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
318
|
my $sp = [@{$self}]; |
|
6
|
|
|
|
|
12
|
|
17
|
6
|
|
|
|
|
51
|
my $bp = $base->parts; |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
|
|
47
|
for (my $i = 0; $i < @$bp; ++$i) { |
20
|
16
|
100
|
50
|
|
|
40
|
$i = @$bp && next if $bp->[$i] ne $sp->[0]; |
21
|
10
|
|
|
|
|
16
|
shift @$sp; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
|
|
13
|
return !!(@$self != @$sp); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub to_rel { |
28
|
5
|
|
|
5
|
1
|
5815
|
my ($self, $base) = @_; |
29
|
5
|
|
|
|
|
20
|
my $x = Mojo::File->new("$self"); |
30
|
5
|
|
|
|
|
1116
|
return $self->new($x->to_rel("$base")->to_string); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub to_subpath_of { |
34
|
4
|
|
|
4
|
1
|
2695
|
my ($self, $base) = @_; |
35
|
4
|
|
|
|
|
18
|
my $clone = $self->clone; |
36
|
4
|
100
|
|
|
|
99
|
return $clone unless $self->is_subpath_of($base); |
37
|
3
|
100
|
|
|
|
34
|
$base = $self->new($base) unless ref($base); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
17
|
my $bp = $base->parts; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
65
|
for (my $i = 0; $i < @$bp; ++$i) { |
42
|
8
|
50
|
0
|
|
|
20
|
$i = @$bp && next if ($bp->[$i] ne $clone->parts->[0]); |
43
|
8
|
|
|
|
|
92
|
shift @{$clone->{parts}}; |
|
8
|
|
|
|
|
19
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
12
|
return $clone->leading_slash(0); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding utf8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=begin html |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=end html |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 NAME |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Mojo::Path::Role::Relative - Relative operations on a Mojo::Path |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$path = Mojo::Path->with_roles('+Relative')->new('/foo/bar/baz/data.json'); |
69
|
|
|
|
|
|
|
$base = Mojo::Path->new('/foo/bar'); |
70
|
|
|
|
|
|
|
# 1 |
71
|
|
|
|
|
|
|
$path->is_subpath_of($base); |
72
|
|
|
|
|
|
|
# "baz/data.json" |
73
|
|
|
|
|
|
|
$path->to_subpath_of($base); |
74
|
|
|
|
|
|
|
# "baz/data.json" |
75
|
|
|
|
|
|
|
$path->to_rel($base); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L was deprecated sometime ago. A suggestion was made to move |
80
|
|
|
|
|
|
|
the functionality to L. This is an implementation of that suggestion |
81
|
|
|
|
|
|
|
as a L. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This role adds the following methods to L when composed. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 is_subpath_of |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 to_rel |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 to_subpath_of |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
kiwiroy - Roy Storey |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LICENSE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This library is free software and may be distributed under the same terms as |
102
|
|
|
|
|
|
|
perl itself. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |