line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package YATT::Lite::Partial::AppPath; sub MY () {__PACKAGE__} |
2
|
19
|
|
|
19
|
|
128
|
use strict; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
560
|
|
3
|
19
|
|
|
19
|
|
93
|
use warnings qw(FATAL all NONFATAL misc); |
|
19
|
|
|
|
|
45
|
|
|
19
|
|
|
|
|
632
|
|
4
|
|
|
|
|
|
|
|
5
|
19
|
|
|
19
|
|
108
|
use File::Path (); |
|
19
|
|
|
|
|
43
|
|
|
19
|
|
|
|
|
494
|
|
6
|
|
|
|
|
|
|
|
7
|
19
|
|
|
|
|
154
|
use YATT::Lite::Partial fields => [qw/cf_^app_root/] |
8
|
19
|
|
|
19
|
|
104
|
, requires => [qw/error rel2abs/]; |
|
19
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Note: Do *not* use YATT::Lite. YATT::Lite *uses* this. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub app_path_expand { |
13
|
6
|
|
|
6
|
0
|
18
|
(my MY $self, my ($path, $in)) = @_; |
14
|
6
|
|
|
|
|
18
|
$self->app_path_is_replaced($path); |
15
|
6
|
|
33
|
|
|
40
|
$self->app_path_normalize($path, $in // $self->{cf_app_root}); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub app_path_is_replaced { |
19
|
51
|
|
|
51
|
0
|
90
|
my MY $self = shift; |
20
|
51
|
|
|
|
|
251
|
$_[0] =~ s|^\@|$self->{cf_app_root}/|; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub app_path_find_dir_in { |
24
|
45
|
|
|
45
|
0
|
96
|
(my MY $self, my ($in, $path)) = @_; |
25
|
45
|
|
|
|
|
128
|
$self->app_path_is_replaced($path); |
26
|
45
|
|
|
|
|
143
|
$path = $self->app_path_normalize($path, $in); |
27
|
45
|
50
|
|
|
|
689
|
-d $path ? $path : ''; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub app_path_normalize { |
31
|
52
|
|
|
52
|
0
|
116
|
(my MY $self, my ($path, $base)) = @_; |
32
|
52
|
100
|
|
|
|
325
|
my $normalized = $path =~ m{^/} ? $path : $self->rel2abs($path, $base); |
33
|
52
|
|
|
|
|
231
|
1 while $normalized =~ s{/[^/\.]+/\.\.(?:/|$)}{/}; |
34
|
|
|
|
|
|
|
# XXX: Should not point outside of $app_root. |
35
|
52
|
|
|
|
|
130
|
$normalized; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub app_path_ensure_existing { |
39
|
0
|
|
|
0
|
0
|
0
|
(my MY $self, my ($path, %opts)) = @_; |
40
|
0
|
0
|
|
|
|
0
|
if ($self->app_path_is_replaced(my $real = $path)) { |
41
|
0
|
0
|
|
|
|
0
|
return $real if -d $real; |
42
|
0
|
|
|
|
|
0
|
File::Path::make_path($real, \%opts); |
43
|
0
|
|
|
|
|
0
|
$real; |
44
|
|
|
|
|
|
|
} else { |
45
|
0
|
0
|
|
|
|
0
|
return $path if -d $path; |
46
|
0
|
|
|
|
|
0
|
$self->error('Non-existing path out of app_path is prohibited: %s', $path); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub app_path { |
51
|
1
|
|
|
1
|
0
|
5
|
(my MY $self, my ($fn, $nocheck)) = @_; |
52
|
1
|
|
|
|
|
5
|
my $path = $self->{cf_app_root}; |
53
|
1
|
|
|
|
|
15
|
$path =~ s|/*$|/$fn|; |
54
|
1
|
50
|
33
|
|
|
57
|
if (not $nocheck and not -e $path) { |
55
|
1
|
|
|
|
|
9
|
$self->error_with_status(404, "Can't find app_path: %s", $path); |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
$path; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub app_path_var { |
61
|
0
|
|
|
0
|
0
|
|
shift->app_path_ensure_existing(join('/', '@var', @_)); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub app_path_var_tmp { |
65
|
0
|
|
|
0
|
0
|
|
shift->app_path_var('tmp', @_); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |