File Coverage

blib/lib/YATT/Lite/Partial/AppPath.pm
Criterion Covered Total %
statement 22 37 59.4
branch 3 12 25.0
condition 0 3 0.0
subroutine 7 11 63.6
pod 0 7 0.0
total 32 70 45.7


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