| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## Apache2 Server Side Include Parser - ~/lib/Apache2/SSI/URI.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.1.3 | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2020/12/18 | ||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ## Modified 2024/09/04 | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | ## All rights reserved | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Apache2::SSI::URI; | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use parent qw( Apache2::SSI::Common ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use vars qw( $VERSION $DEBUG $DIR_SEP ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use Apache2::SSI::Finfo; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 9 | require constant; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use constant URI_CLASS => 'URI'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use URI::file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | if( $ENV{MOD_PERL} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | require Apache2::RequestRec; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | require Apache2::RequestUtil; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | require Apache2::SubRequest; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | require Apache2::Access; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | require Apache2::Const; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | Apache2::Const->import( compile => qw( :common :http OK DECLINED ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | our( $DEBUG ); | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 23 | ▶ | q{""} => sub { $_[0]->document_uri->as_string }, | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | bool => sub () { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | our $VERSION = 'v0.1.3'; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | our $DIR_SEP = $Apache2::SSI::Common::DIR_SEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # document_root = /home/joe/www | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # base_uri = /my/uri/file.html/some/path/info?q=something&l=ja_JP | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # base_uri is the current reference document | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # document_uri = ./about.html | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # document_uri is the uri which is the purpose of this object. It will be made absolute and its dots flattened | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Example: ../about.html?q=hello would become /my/about.html?q=hello | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | sub init | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 65 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 65 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 65 | $self->{apache_request} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 65 | ▶ | $self->{base_uri} = '/' unless( length( $self->{base_uri} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # By default | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 65 | $self->{code} = 200; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 65 | $self->{document_path} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 65 | $self->{document_root} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Reference document for the main request | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 65 | $self->{document_uri} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 65 | $self->{filepath} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 65 | $self->{finfo} = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 65 | $self->{_init_params_order} = [qw( apache_request document_root base_uri document_uri document_path filepath )]; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 65 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 65 | ▶ | $self->SUPER::init( @_ ) || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 65 | $self->{_env} = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 65 | $self->{_path_info_processed} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 65 | $self->{_uri_reset} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 65 | ▶ | $self->{document_root} ||= $self->env( 'DOCUMENT_ROOT' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"document_root"} ||= $self->env("DOCUMENT_ROOT")
MC/DC0%0/2
$self->{"document_root"} ||= $self->env("DOCUMENT_ROOT")
$self->{"document_root"}
$self->env("DOCUMENT_ROOT")
Truth table33%1/3
A ||= B
A= $self->{"document_root"}B= $self->env("DOCUMENT_ROOT")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 65 | ▶ | $self->{base_uri} ||= $self->env( 'DOCUMENT_URI' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"base_uri"} ||= $self->env("DOCUMENT_URI")
MC/DC0%0/2
$self->{"base_uri"} ||= $self->env("DOCUMENT_URI")
$self->{"base_uri"}
$self->env("DOCUMENT_URI")
Truth table33%1/3
A ||= B
A= $self->{"base_uri"}B= $self->env("DOCUMENT_URI")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 65 | ▶ | return( $self->error( "No document root was provided." ) ) if( !length( $self->{document_root} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 65 | ▶ | return( $self->error( "No base uri was provided." ) ) if( !length( $self->{base_uri} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 65 | ▶ | return( $self->error( "No document uri was provided." ) ) if( !length( $self->{document_uri} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Small correction if necessary. If the base uri is a directory, it needs to have a trailing "/", so URI knows this is a directory and not a file. | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # URI->new( "./file.pl" )->abs( "/ssi/plop" ) becomes "/ssi/file.pl" whereas it should be /ssi/plop/file.pl | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # $self->{base_uri} .= '/' if( length( $self->{base_uri} ) && -d( "$self->{document_root}$self->{base_uri}" ) && substr( $self->{base_uri}, -1, 1 ) ne '/' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 65 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1157 | ▶ | sub apache_request { return( shift->_set_get_object_without_init( 'apache_request', 'Apache2::RequestRec', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apache_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | sub base_dir | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base_dir: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return( $self->{base_dir} ) if( length( $self->{base_dir} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Just in case | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return( $self->root ) if( !length( $self->{base_uri} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $base = $self->base_uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return( $self->error( "No base uri defined." ) ) if( !length( $base ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $path = $base->document_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my @segments = split( '/', $path, -1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | pop( @segments ); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return( $base ) if( !scalar( @segments ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $dir_path = join( '/', @segments ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $rr = $self->lookup_uri( $dir_path ); | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if( !defined( $rr ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif( $rr->status != &Apache2::Const::HTTP_OK ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return( $self->error( "Could not look up base directory \"$dir_path\". Returned code is: ", $rr->status ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | elsif( $rr->finfo->filetype == &APR::Const::FILETYPE_NOFILE ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return( $self->error( "Could not find base directory \"$dir_path\"." ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Remove trailing slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $u = $self->_trim_trailing_slash( $rr->uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $hash = | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | apache_request => $self->apache_request, | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | base_dir => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | base_uri => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | document_path => "$u", | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | document_root => $rr->document_root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | document_uri => "$u", | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | filename => $rr->filename, | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | path_info => $rr->path_info, | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | query_string => scalar( $rr->args ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | _path_info_processed => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $hash = | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | base_dir => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | base_uri => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | document_path => $dir_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | document_root => $self->document_root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | document_uri => $dir_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | filename => $self->document_root . $dir_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | path_info => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | query_string => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | _path_info_processed => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->{base_dir} = bless( $hash => ref( $self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return( $self->{base_dir} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | sub base_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
base_uri: called CC=14 SCAR=33.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 15 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 15 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 15 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | $new = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | elsif( !ref( $self->{base_uri} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $new = $self->{base_uri}; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 15 | ▶ | unless( length( $new ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 7 | return( $self->{base_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | # We create an URI object, so we can get the path only | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | my $u = $self->new_uri( $new ); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | my $path = $u->path; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 8 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $rr = $self->lookup_uri( $path ); | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if( !defined( $rr ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif( $rr->status != &Apache2::Const::HTTP_OK ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $hdrs = $rr->headers_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | return( $self->error( "Could not look up uri \"$path\". Returned code is: ", $rr->status ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | elsif( $rr->finfo->filetype == &APR::Const::FILETYPE_NOFILE ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return( $self->error( "Could not find uri \"$path\" (originally $u)." ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # Remove trailing slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $u2 = $self->_trim_trailing_slash( $rr->unparsed_uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $hash = | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | apache_request => $r, | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | base_dir => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | base_uri => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | document_path => substr( $u2->path, 0, length( $u2->path ) - length( $rr->path_info ) ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | document_root => $self->document_root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | document_uri => $u2, | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | filename => $rr->filename, | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | path_info => $rr->path_info, | ||||||||||||||||||||||||||||||||||||||||||||||
| 207 | query_string => scalar( $rr->args ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | _path_info_processed => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if( $rr->finfo->filetype == &APR::Const::FILETYPE_DIR ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->{base_dir} = bless( $hash => ref( $self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $self->{base_uri} = bless( $hash => ref( $self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # We need to ensure the base uri is free of any path info or query string ! | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | my $ref = $self->_find_path_info( $u->path ); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | ▶ | if( !defined( $ref ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | return( $self->error( "Unable to resolve \"$u\"." ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | elsif( $ref->{code} != 200 ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $self->error( "Failed to resolve \"$u\". Resulting code is '$ref->{code}'." ); | |||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | my $hash = | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | base_dir => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | base_uri => $self->root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | document_path => $ref->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | document_root => $self->document_root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | filename => $ref->{filepath}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | path_info => $ref->{path_info}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | query_string => $ref->{query_string}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | _path_info_processed => 1, | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | ▶ | my $tmp = $self->new_uri( $ref->{path_info} ? join( '', $ref->{path}, $ref->{path_info} ) : $ref->{path} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | ▶ | $tmp->query( $ref->{query_string} ) if( $ref->{query_string} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | $hash->{document_uri} = $tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 8 | ▶ | $self->{base_dir} = bless( $hash => ref( $self ) ) if( -d( $ref->{path} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 8 | $self->{base_uri} = bless( $hash => ref( $self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | return( $self->{base_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | sub clone | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $new = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my @fields = grep( !/^(apache_request|finfo)$/, keys( %$self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | @$new{ @fields } = @$self{ @fields }; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $new->{apache_request} = $self->{apache_request}; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $env = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | %$env = %{$self->{_env}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $new->{_env} = $env; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | return( bless( $new => ( ref( $self ) || $self ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | sub code | ||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 113 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
code: called CC=4 SCAR=15.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 113 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 113 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 265 | 113 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $r->status( @_ ) if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | return( $r->status ); | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 113 | ▶ | $self->{code} = shift( @_ ) if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 113 | return( int( $self->{code} ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub document_dir { return( shift->document_directory( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_dir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | sub document_directory | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_directory: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | my $doc_path = $self->document_path || return( $self->error( "No document path set." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->document_path || (return $self->error('No document path set.'))
MC/DC0%0/1
$self->document_path || (return $self->error('No document path set.'))
$self->document_path
Truth table0%0/2
A
A= $self->document_path
| |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my $doc_root = $self->document_root || return( $self->error( "No document root set." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->document_root || (return $self->error('No document root set.'))
MC/DC0%0/1
$self->document_root || (return $self->error('No document root set.'))
$self->document_root
Truth table0%0/2
A
A= $self->document_root
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | return( $self->make( document_uri => $doc_path ) ) if( -e( "${doc_root}${doc_path}" ) && -d( _ ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e "$doc_root$doc_path" and -d _
MC/DC0%0/2
-e "$doc_root$doc_path" and -d _
-e "$doc_root$doc_path"
-d _
Truth table0%0/3
A and B
A= -e "$doc_root$doc_path"B= -d _
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return( $parent ); | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | sub document_filename { return( shift->filename( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_filename: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | sub document_path | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 74 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_path: called CC=10 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 74 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | 74 | my $class = ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 74 | ▶ | my $caller = (caller(1))[3] // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(caller 1)[3] // ""
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table50%1/2
A
A= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # my $caller = substr( $sub, rindex( $sub, ':' ) + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 74 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | 74 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | my $uri = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $rr = $self->lookup_uri( $uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if( !defined( $rr ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my $u = APR::URI->parse( $rr->pool, $r->uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | # Remove trailing slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $u2 = $self->_trim_trailing_slash( $u->rpath ); | |||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->{document_path} = $u2; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | $self->{_uri_reset} = 'document_path' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | elsif( !length( $self->{document_path} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $u = APR::URI->parse( $r->pool, $r->uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $self->{document_path} = $self->new_uri( $u->rpath ); | |||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 74 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 74 | my $uri = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 74 | $self->{document_path} = $self->new_uri( $self->collapse_dots( $uri ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 74 | ▶ | $self->{_uri_reset} = 'document_path' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 74 | return( $self->{document_path} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||
| 333 | sub document_root | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 311 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_root: called CC=7 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 311 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 311 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 337 | 311 | my $new; | |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 311 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 65 | $new = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | # unless( substr( $new, 0, 1 ) eq '/' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 65 | ▶ | unless( File::Spec->file_name_is_absolute( $new ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | $new = URI::file->new_abs( $new )->file( $^O ); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 311 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | ▶ | $r->document_root( $new ) if( defined( $new ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $r->subprocess_env( DOCUMENT_ROOT => $r->document_root ); | |||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | return( $r->document_root ); | |||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 354 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 311 | ▶ | if( defined( $new ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 65 | $self->{document_root} = $new; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 65 | $self->_set_env( DOCUMENT_ROOT => $self->{document_root} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 311 | ▶ | return( $self->{document_root} || $self->env( 'DOCUMENT_ROOT' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'document_root'} || $self->env('DOCUMENT_ROOT')
MC/DC0%0/2
$self->{'document_root'} || $self->env('DOCUMENT_ROOT')
$self->{'document_root'}
$self->env('DOCUMENT_ROOT')
Truth table33%1/3
A || B
A= $self->{'document_root'}B= $self->env('DOCUMENT_ROOT')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | sub document_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 94 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
document_uri: called CC=26 SCAR=49.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 94 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 368 | 94 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 94 | my $new = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 94 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 371 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 65 | $new = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | 65 | local $URI::ABS_REMOTE_LEADING_DOTS = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 374 | 65 | ▶ | unless( substr( "$new", 0, 1 ) eq '/' ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 8 | my $base_uri = $self->base_uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | 8 | $new = URI->new( $new )->abs( $base_uri->{document_path} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # return( $self->error( "Document URI needs to be an absolute URL path. Value provided was '$new'." ) ) if( length( $new ) && substr( $new, 0, 1 ) ne '/' ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 94 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | # We do a lookup unless we are already in a sub request, and we do not want to end up in an infinite loop | ||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | if( length( "$new" ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | my $rr = $self->lookup_uri( "$new" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if( !defined( $rr ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->apache_request( $rr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | # Remove trailing slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $u = $self->_trim_trailing_slash( $rr->unparsed_uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->{document_uri} = $u; | |||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $self->_set_env( DOCUMENT_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self->_set_env( REQUEST_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | $self->_set_env( QUERY_STRING => scalar( $rr->args ) ) if( scalar( $rr->args ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | $self->_set_env( PATH_INFO => $rr->path_info ) if( $rr->path_info ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 404 | elsif( $self->{_uri_reset} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | my $u = URI->new( $r->uri . ( $r->path_info // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$r->path_info // ""
MC/DC0%0/1
$r->path_info // ""
$r->path_info
Truth table0%0/2
A
A= $r->path_info
| |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | $u->query( scalar( $r->args ) ) if( length( scalar( $r->args ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # Cannot change the value of $r->unparsed_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $r->uri( "$u" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $self->{document_uri} = $u; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->{_uri_reset} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 413 | elsif( !length( $self->{document_uri} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $self->{document_uri} = $self->new_uri( $r->unparsed_uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $self->_set_env( DOCUMENT_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $self->_set_env( REQUEST_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | $self->_set_env( QUERY_STRING => scalar( $r->args ) ) if( scalar( $r->args ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | $self->_set_env( PATH_INFO => $r->path_info ) if( $r->path_info ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return( $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 423 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 424 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 94 | ▶ | if( length( "$new" ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 426 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 65 | $self->{_path_info_processed} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 94 | ▶ | return( '' ) if( !length( $self->{document_uri} ) && $self->{_path_info_processed} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not length $self->{"document_uri"} and $self->{"_path_info_processed"}
MC/DC0%0/2
not length $self->{"document_uri"} and $self->{"_path_info_processed"}
not length $self->{"document_uri"}
$self->{"_path_info_processed"}
Truth table66%2/3
not(A) and B
A= not length $self->{"document_uri"}B= $self->{"_path_info_processed"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 94 | ▶ | my $v = $new || $self->{document_uri}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$new || $self->{'document_uri'}
MC/DC0%0/2
$new || $self->{'document_uri'}
$new
$self->{'document_uri'}
Truth table66%2/3
A || B
A= $newB= $self->{'document_uri'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 94 | ▶ | if( !$self->{_path_info_processed} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 74 | $self->{_path_info_processed}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 434 | 74 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | 74 | ▶ | if( defined( $res = $self->_find_path_info( $v ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 74 | $self->{document_uri} = URI->new( $v ); | |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 74 | $self->document_path( $res->{path} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 439 | 74 | $self->filename( $res->{filepath} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 440 | 74 | ▶ | $self->path_info( $res->{path_info} ) if( length( $res->{path_info} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 74 | ▶ | $self->query_string( $res->{query_string} ) if( length( $res->{query_string} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 74 | $self->_set_env( DOCUMENT_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | 74 | $self->_set_env( REQUEST_URI => $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 444 | 74 | $self->code( $res->{code} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 446 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 447 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 94 | ▶ | if( $self->{_uri_reset} ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 452 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | $self->{_uri_reset} = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my $u = URI->new( $self->document_path . ( $self->path_info // '' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->path_info // ""
MC/DC0%0/1
$self->path_info // ""
$self->path_info
Truth table0%0/2
A
A= $self->path_info
| |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $u->query( $self->query_string ) if( $self->query_string ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->{document_uri} = $u; | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 94 | return( $self->{document_uri} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||
| 462 | sub env | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 74 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
env: called CC=13 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 74 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 465 | # The user wants the entire hash reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 74 | ▶ | unless( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | return( $r->subprocess_env ) | |||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 474 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 475 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | unless( scalar( keys( %{$self->{_env}} ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $self->{_env} = {%ENV}; | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return( $self->{_env} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 74 | my $name = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 484 | 74 | ▶ | return( $self->error( "No environment variable name was provided." ) ) if( !length( $name ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 74 | my $opts = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | 9 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 74 | ▶ | $opts = pop( @_ ) if( scalar( @_ ) && Scalar::Util::reftype( $_[-1] ) eq 'HASH' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
scalar @_ and builtin::reftype($_[-1]) eq "HASH"
MC/DC0%0/2
scalar @_ and builtin::reftype($_[-1]) eq "HASH"
scalar @_
builtin::reftype($_[-1]) eq "HASH"
Truth table33%1/3
A and B
A= scalar @_B= builtin::reftype($_[-1]) eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # return( $self->error( "Environment variable value provided is a reference data (", overload::StrVal( $val ), ")." ) ) if( ref( $val ) && ( !overload::Overloaded( $val ) || ( overload::Overloaded( $val ) && !overload::Method( $val, '""' ) ) ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 74 | ▶ | my $r = $opts->{apache_request} || $self->apache_request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{'apache_request'} || $self->apache_request
MC/DC0%0/2
$opts->{'apache_request'} || $self->apache_request
$opts->{'apache_request'}
$self->apache_request
Truth table33%1/3
A || B
A= $opts->{'apache_request'}B= $self->apache_request
| |||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 74 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | $r->subprocess_env( $name => shift( @_ ) ) if( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my $v = $r->subprocess_env( $name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | return( $v ); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 497 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 498 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 74 | my $env = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 500 | 74 | ▶ | unless( scalar( keys( %{$self->{_env}} ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # Make a copy of the environment variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 9 | $self->{_env} = {%ENV}; | |||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 74 | $env = $self->{_env}; | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 74 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 74 | $env->{ $name } = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 509 | 74 | my $meth = lc( $name ); | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | 74 | ▶ | if( $self->can( $meth ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $self->$meth( $env->{ $name } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 74 | return( $env->{ $name } ); | |||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # This is set by document_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 520 | sub filename | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 135 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filename: called CC=16 SCAR=39.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 135 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | 135 | my $class = ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 524 | 135 | ▶ | my $caller = (caller(1))[3] // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(caller 1)[3] // ""
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table50%1/2
A
A= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | # my $caller = substr( $sub, rindex( $sub, ':' ) + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 135 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 527 | 135 | my $newfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | 135 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 529 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 74 | $newfile = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | 74 | ▶ | return( $self->error( "New file provided, but it was an empty string." ) ) if( !defined( $newfile ) || !length( $newfile ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $newfile and length $newfile
MC/DC0%0/2
defined $newfile and length $newfile
defined $newfile
length $newfile
Truth table33%1/3
A and B
A= defined $newfileB= length $newfile
| |||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 135 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 535 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | if( defined( $newfile ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 537 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | $r = $r->is_initial_req ? $r : $r->main; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $rr = $r->lookup_file( $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if( $rr->status == &Apache2::Const::HTTP_OK ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 541 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $newfile = $rr->filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 544 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 545 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | $r->filename( $self->collapse_dots( $newfile, { separator => $DIR_SEP }) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | # <https://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#toc_C_filename_> | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | $r->finfo( APR::Finfo::stat( $newfile, &APR::Const::FINFO_NORM, $r->pool ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $self->finfo( $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $r->subprocess_env( SCRIPT_FILENAME => $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | # Force to create new Apache2::SSI::URI object | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | $self->{filename} = $newfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | $self->{_uri_reset} = 'filename' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 556 | elsif( !length( $self->{filename} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 557 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $self->{filename} = $r->filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 562 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 135 | ▶ | if( defined( $newfile ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 564 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 74 | my $try = Cwd::realpath( $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 566 | # Cwd::realpath would convert | ||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # Z:\perl\Apache2-SSI\t\htdocs\ssi\include.cgi | ||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # into | ||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # Z:/perl/Apache2-SSI/t/htdocs/ssi/include.cgi | ||||||||||||||||||||||||||||||||||||||||||||||
| 570 | # amazingly enough, so to make sure this keeps working on windows related platform, we need to call URI::file | ||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 74 | ▶ | $newfile = URI::file->new( $try )->file( $^O ) if( defined( $try ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 74 | ▶ | unless( File::Spec->file_name_is_absolute( $newfile ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $newfile = URI::file->new_abs( $newfile )->file( $^O ); | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 74 | $self->env( SCRIPT_FILENAME => $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 577 | 74 | $self->finfo( $newfile ); | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | # Force to create new Apache2::SSI::URI object | ||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # Either a URI object or an URI::file object | ||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 74 | $self->{filename} = $self->collapse_dots( $newfile, { separator => $DIR_SEP })->file( $^O ); | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | # Pass the file as new argument to URI::file which will create an object based on the value of the current OS | ||||||||||||||||||||||||||||||||||||||||||||||
| 582 | # and transform it into a path à la linux, which is same as web, which is what we want | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | # All this is unnecessary for linux type system or those who use / as directory separator, | ||||||||||||||||||||||||||||||||||||||||||||||
| 584 | # but for windows type systems this is necessary | ||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 74 | ▶ | if( CORE::index( $self->{filename}, $self->document_root ) != -1 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 74 | $self->{document_path} = $self->new_uri( URI::file->new( substr( $self->{filename}, length( $self->document_root ) ) )->file( 'linux' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 589 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 590 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->{document_path} = $self->new_uri( URI::file->new( $self->{filename} )->file( 'linux' ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 74 | ▶ | $self->{_uri_reset} = 'filename' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 135 | return( $self->{filename} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # Alias | ||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 26 | ▶ | sub filepath { return( shift->filename( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filepath: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | sub finfo | ||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 77 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finfo: called CC=9 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 77 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 605 | 77 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | 77 | my $newfile; | |||||||||||||||||||||||||||||||||||||||||||||
| 607 | 77 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 608 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 74 | $newfile = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 610 | 74 | ▶ | return( $self->error( "New file path specified but is an empty string." ) ) if( !defined( $newfile ) || !length( $newfile ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $newfile and length $newfile
MC/DC0%0/2
defined $newfile and length $newfile
defined $newfile
length $newfile
Truth table33%1/3
A and B
A= defined $newfileB= length $newfile
| |||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 612 | elsif( !$self->{finfo} ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 613 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | $newfile = $self->filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | return( $self->error( "No file path set. This should not happen." ) ) if( !$newfile ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 77 | ▶ | if( defined( $newfile ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 619 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 74 | ▶ | $self->{finfo} = Apache2::SSI::Finfo->new( $newfile, ( $r ? ( apache_request => $r ) : () ), debug => $self->debug ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 74 | ▶ | return( $self->pass_error( Apache2::SSI::Finfo->error ) ) if( !$self->{finfo} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 77 | return( $self->{finfo} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||
| 626 | sub lookup_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_uri: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $uri = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | $uri = shift( @_ ) if( @_ && !ref( $_[0] ) && ( scalar( @_ ) % 2 ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@_ and not ref $_[0] and scalar(@_) % 2
@_ and not ref $_[0]
MC/DC0%0/3
@_ and not ref $_[0] and scalar(@_) % 2
@_
not ref $_[0]
scalar(@_) % 2
Truth table0%0/4
A and not(B) and C
A= @_B= not ref $_[0]C= scalar(@_) % 2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $opts = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | $uri = $opts->{uri} if( !length( $uri ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | return( $self->error( "No uri provided." ) ) if( !length( $uri ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | my $r = $opts->{apache_request} || $self->apache_request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{'apache_request'} || $self->apache_request
MC/DC0%0/2
$opts->{'apache_request'} || $self->apache_request
$opts->{'apache_request'}
$self->apache_request
Truth table0%0/3
A || B
A= $opts->{'apache_request'}B= $self->apache_request
| |||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | my $max_redirects = $opts->{max_redirect} || 10; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts->{'max_redirect'} || 10
MC/DC0%0/1
$opts->{'max_redirect'} || 10
$opts->{'max_redirect'}
Truth table0%0/2
A
A= $opts->{'max_redirect'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | my $rr = $r->lookup_uri( $uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | ▶ | while( ++$c <= $max_redirects && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
++$c <= $max_redirects and $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
$rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY or $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
MC/DC0%0/3
++$c <= $max_redirects and $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
++$c <= $max_redirects
$rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY
$rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
Truth table0%0/4
A and B or C
A= ++$c <= $max_redirectsB= $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLYC= $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
| |||||||||||||||||||||||||||||||||||||||||||||||
| 639 | ( $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || | ||||||||||||||||||||||||||||||||||||||||||||||
| 640 | $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 641 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my $next_r = $rr->next; | |||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | if( !defined( $next_r ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 644 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 647 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 648 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $rr = $next_r; | |||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | if( defined( $rr ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $rr and $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
$rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY or $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
MC/DC0%0/3
defined $rr and $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
defined $rr
$rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY
$rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
Truth table0%0/4
A and B or C
A= defined $rrB= $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLYC= $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY
| |||||||||||||||||||||||||||||||||||||||||||||||
| 653 | ( $rr->status == &Apache2::Const::HTTP_MOVED_PERMANENTLY || | ||||||||||||||||||||||||||||||||||||||||||||||
| 654 | $rr->status == &Apache2::Const::HTTP_MOVED_TEMPORARILY ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 655 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my $hdrs = $rr->headers_out; | |||||||||||||||||||||||||||||||||||||||||||||
| 657 | # Weird, should not happen, but just in case | ||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | if( !exists( $hdrs->{Location} ) || !length( $hdrs->{Location} ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $hdrs->{"Location"} and length $hdrs->{"Location"}
MC/DC0%0/2
exists $hdrs->{"Location"} and length $hdrs->{"Location"}
exists $hdrs->{"Location"}
length $hdrs->{"Location"}
Truth table0%0/3
A and B
A= exists $hdrs->{"Location"}B= length $hdrs->{"Location"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 659 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | return( $rr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 664 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 665 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 667 | # No, we cannot use $rr->uri. This would give us the initial requested uri, not the redirected uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my $u = URI->new( $hdrs->{Location} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | $uri = $u->path; | |||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | if( ++$self->{_lookup_looping} > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 671 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | return( $rr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 674 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 675 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | delete( $self->{_lookup_looping} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | my $new_r = $self->lookup_uri( $uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | return( $new_r ); | |||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 680 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 682 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | $self->error( "An error occurred while creating URI object for \"$hdrs->{Location}\": $@" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return( $rr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | return( $rv ); | |||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | return( $rr ); | |||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||
| 691 | sub make | ||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | ▶ | return( $self->error( "Must be called with an existing object and not as ", __PACKAGE__, "->make()" ) ) if( !Scalar::Util::blessed( $self ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | my $p = $self->_get_args_as_hash( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | my $d = $self->document_root; | |||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my $b = $self->base_uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | my $f = $self->document_uri; | |||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | $p->{apache_request} = $r if( !$p->{apache_request} && $r ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $p->{"apache_request"} and $r
MC/DC0%0/2
not $p->{"apache_request"} and $r
not $p->{"apache_request"}
$r
Truth table0%0/3
not(A) and B
A= not $p->{"apache_request"}B= $r
| |||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | ▶ | $p->{document_root} = "$d" if( !$p->{document_root} && length( $d ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $p->{"document_root"} and length $d
MC/DC0%0/2
not $p->{"document_root"} and length $d
not $p->{"document_root"}
length $d
Truth table0%0/3
not(A) and B
A= not $p->{"document_root"}B= length $d
| |||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | $p->{base_uri} = "$b" if( !$p->{base_uri} && length( $b ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $p->{"base_uri"} and length $b
MC/DC0%0/2
not $p->{"base_uri"} and length $b
not $p->{"base_uri"}
length $b
Truth table0%0/3
not(A) and B
A= not $p->{"base_uri"}B= length $b
| |||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 0 | ▶ | $p->{document_uri} = "$f" if( !$p->{document_uri} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | $p->{debug} = $self->debug if( !length( $p->{debug} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | return( $self->new( $p ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||
| 708 | sub new_uri | ||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 172 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_uri: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 172 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 711 | 172 | my $class = URI_CLASS; | |||||||||||||||||||||||||||||||||||||||||||||
| 712 | 172 | my $uri = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 713 | 172 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||
| 714 | # try-catch | ||||||||||||||||||||||||||||||||||||||||||||||
| 715 | my $rv = eval | ||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 172 | { | |||||||||||||||||||||||||||||||||||||||||||||
| 717 | 172 | return( $class->new( $uri ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 718 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 172 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 720 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | return( $self->error( "Unable to instantiate an URI object with \"$uri\": $@" ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 172 | return( $rv ); | |||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||
| 726 | sub parent | ||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | my $path = $self->document_path; | |||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 731 | # I deliberately did not do split( '/', $path, -1 ) so that if there is a trailing '/', it will not be counted | ||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | my @segments = $self->document_path->path_segments; | |||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | pop( @segments ); | |||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | return( $self ) if( !scalar( @segments ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | return( $self->make( document_uri => join( '/', @segments ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||
| 738 | sub path_info | ||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_info: called CC=7 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 741 | 5 | my $class = ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 742 | 5 | ▶ | my $caller = (caller(1))[3] // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(caller 1)[3] // ""
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table50%1/2
A
A= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # my $caller = substr( $sub, rindex( $sub, ':' ) + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 5 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 745 | 5 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 746 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 748 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $r->path_info( shift( @_ ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | $self->_set_env( PATH_INFO => $r->path_info ); | |||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | ▶ | $self->{_uri_reset} = 'path_info' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 0 | return( $r->path_info ); | |||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 755 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 756 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 5 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 758 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | $self->{path_info} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | $self->_set_env( PATH_INFO => $self->{path_info} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 761 | 3 | ▶ | $self->{_uri_reset} = 'path_info' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 5 | return( $self->{path_info} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||
| 767 | sub query_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 24 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_string: called CC=7 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 24 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 770 | 24 | my $class = ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 771 | 24 | ▶ | my $caller = (caller(1))[3] // ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
(caller 1)[3] // ""
MC/DC0%0/1
(caller 1)[3] // ""
(caller 1)[3]
Truth table50%1/2
A
A= (caller 1)[3]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # my $caller = substr( $sub, rindex( $sub, ':' ) + 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 24 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 774 | 24 | ▶ | if( $r ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 775 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 777 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | my $qs = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $r->args( $qs ); | |||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $self->_set_env( QUERY_STRING => $qs ); | |||||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | ▶ | $self->{_uri_reset} = 'query_string' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | return( $r->args ); | |||||||||||||||||||||||||||||||||||||||||||||
| 784 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 785 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 786 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 24 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 788 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 18 | $self->{query_string} = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 790 | 18 | $self->_set_env( QUERY_STRING => $self->{query_string} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 791 | 18 | ▶ | $self->{_uri_reset} = 'query_string' unless( $caller eq "${class}\::document_uri" ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 792 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 24 | return( $self->{query_string} ); | |||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||
| 797 | sub root | ||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 16 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 800 | 16 | ▶ | return( $self->{root} ) if( $self->{root} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 8 | my $hash = | |||||||||||||||||||||||||||||||||||||||||||||
| 802 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 803 | code => 200, | ||||||||||||||||||||||||||||||||||||||||||||||
| 804 | document_uri => $self->new_uri( '/' ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 805 | document_root => $self->document_root, | ||||||||||||||||||||||||||||||||||||||||||||||
| 806 | debug => $self->debug, | ||||||||||||||||||||||||||||||||||||||||||||||
| 807 | path_info => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 808 | query_string => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 809 | _path_info_processed => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 810 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 8 | $hash->{document_path} = $hash->{document_uri}; | |||||||||||||||||||||||||||||||||||||||||||||
| 812 | 8 | ▶ | $hash->{apache_request} = $self->apache_request if( $self->apache_request ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 8 | my $root = bless( $hash => ref( $self ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 814 | # Scalar::Util::weaken( $copy ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 8 | $root->{base_dir} = $root; | |||||||||||||||||||||||||||||||||||||||||||||
| 816 | 8 | $root->{base_uri} = $root; | |||||||||||||||||||||||||||||||||||||||||||||
| 817 | 8 | $self->{root} = $root; | |||||||||||||||||||||||||||||||||||||||||||||
| 818 | 8 | return( $root ); | |||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # shortcut | ||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | sub uri { return( shift->document_uri( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uri: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||||||
| 824 | # Path info works as a path added to a document uri, such as: | ||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # /my/doc.html/path/info | ||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # But we need to distinguish with missing document hierarchy inside a directory, such as: | ||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # /my/folder/missing_doc.html/path/info | ||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # otherwise we would be treating /missing_doc.html/path/info as a path info | ||||||||||||||||||||||||||||||||||||||||||||||
| 829 | sub _find_path_info | ||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 82 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_path_info: called CC=19 SCAR=31.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 82 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 832 | 82 | my( $uri_path, $doc_root ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 833 | 82 | ▶ | $doc_root //= $self->document_root; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$doc_root //= $self->document_root
MC/DC0%0/2
$doc_root //= $self->document_root
$doc_root
$self->document_root
Truth table33%1/3
A //= B
A= $doc_rootB= $self->document_root
| |||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 82 | my $qs = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 835 | 82 | my $sep = $DIR_SEP; | |||||||||||||||||||||||||||||||||||||||||||||
| 836 | 82 | ▶ | $sep = '/' if( !length( $sep ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 82 | ▶ | if( Scalar::Util::blessed( $uri_path ) && $uri_path->isa( 'URI::file' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($uri_path) and $uri_path->isa("URI::file")
MC/DC0%0/2
builtin::blessed($uri_path) and $uri_path->isa("URI::file")
builtin::blessed($uri_path)
$uri_path->isa("URI::file")
Truth table66%2/3
A and B
A= builtin::blessed($uri_path)B= $uri_path->isa("URI::file")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 838 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | $uri_path = $uri_path->file; | |||||||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 82 | my $u = $self->collapse_dots( $uri_path ); | |||||||||||||||||||||||||||||||||||||||||||||
| 842 | 82 | $qs = $u->query; | |||||||||||||||||||||||||||||||||||||||||||||
| 843 | 82 | $uri_path = $u->path; | |||||||||||||||||||||||||||||||||||||||||||||
| 844 | # Pass the OS to ensure we get ./ss/include.cgi becomes .\ssi\include.cgi | ||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 82 | my $path = URI::file->new( $uri_path )->file( $^O ); | |||||||||||||||||||||||||||||||||||||||||||||
| 846 | 82 | ▶ | $doc_root = $doc_root->file( $^O ) if( Scalar::Util::blessed( $doc_root ) && $doc_root->isa( 'URI::file' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($doc_root) and $doc_root->isa("URI::file")
MC/DC0%0/2
builtin::blessed($doc_root) and $doc_root->isa("URI::file")
builtin::blessed($doc_root)
$doc_root->isa("URI::file")
Truth table33%1/3
A and B
A= builtin::blessed($doc_root)B= $doc_root->isa("URI::file")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 82 | ▶ | $doc_root = substr( $doc_root, 0, length( $doc_root ) - length( $sep ) ) if( substr( $doc_root, -length( $sep ), length( $sep ) ) eq $sep ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 82 | ▶ | return( $self->error( "URI path must be an absolute path starting with '/'. Path provided was \"$uri_path\"." ) ) if( substr( $uri_path, 0, 1 ) ne '/' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 849 | # No need to go further | ||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 82 | ▶ | if( -e( "${doc_root}${path}" ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 851 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 852 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 75 | filepath => "${doc_root}${path}", | |||||||||||||||||||||||||||||||||||||||||||||
| 854 | path => $uri_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 855 | query_string => $qs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 856 | code => 200, | ||||||||||||||||||||||||||||||||||||||||||||||
| 857 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 859 | elsif( $uri_path eq '/' ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 860 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 861 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | filepath => $doc_root, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 863 | path => $uri_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 864 | path_info => undef(), | ||||||||||||||||||||||||||||||||||||||||||||||
| 865 | query_string => $qs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 866 | code => ( -e( $doc_root ) ? 200 : 404 ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 867 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 7 | my @parts = split( '/', substr( $uri_path, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 870 | 7 | my $trypath = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 871 | 7 | my $trypath_uri = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 872 | 7 | my $pathinfo = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 873 | 7 | foreach my $p ( @parts ) | |||||||||||||||||||||||||||||||||||||||||||||
| 874 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # The last path was a directory, and we cannot find the element within. So, the rest of the path is not path info, but rather a 404 missing document hierarchy | ||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # We test the $pathinfo string, so we do not bother checking further if it is already set. | ||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 16 | ▶ | if( !$pathinfo && -d( "${doc_root}${trypath}" ) && !-e( "${doc_root}${trypath}/${p}" ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
not $pathinfo and -d "$doc_root$trypath" and not -e "$doc_root$trypath/$p"
not $pathinfo and -d "$doc_root$trypath"
MC/DC66%2/3
not $pathinfo and -d "$doc_root$trypath" and not -e "$doc_root$trypath/$p"
not $pathinfo
-d "$doc_root$trypath"
not -e "$doc_root$trypath/$p"
Truth table75%3/4
not(A) and B and not(C)
A= not $pathinfoB= -d "$doc_root$trypath"C= not -e "$doc_root$trypath/$p"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 878 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # We return the original path provided (minus any query string) | ||||||||||||||||||||||||||||||||||||||||||||||
| 880 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 3 | ▶ | filepath => $doc_root . ( length( $trypath ) ? $trypath : $path ), | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 882 | path => $uri_path, | ||||||||||||||||||||||||||||||||||||||||||||||
| 883 | code => 404, | ||||||||||||||||||||||||||||||||||||||||||||||
| 884 | query_string => $qs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 885 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 887 | ▶ | elsif( !$pathinfo && -e( "${doc_root}${trypath}/${p}" ) ) | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $pathinfo and -e "$doc_root$trypath/$p"
MC/DC50%1/2
not $pathinfo and -e "$doc_root$trypath/$p"
not $pathinfo
-e "$doc_root$trypath/$p"
Truth table66%2/3
not(A) and B
A= not $pathinfoB= -e "$doc_root$trypath/$p"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 888 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 9 | $trypath_uri .= "/${p}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 890 | 9 | $trypath .= "${sep}${p}"; | |||||||||||||||||||||||||||||||||||||||||||||
| 891 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 892 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 893 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 4 | $pathinfo .= "/$p"; | |||||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 897 | return({ | ||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 4 | filepath => "${doc_root}${trypath}", | |||||||||||||||||||||||||||||||||||||||||||||
| 899 | path => $trypath_uri, | ||||||||||||||||||||||||||||||||||||||||||||||
| 900 | path_info => $pathinfo, | ||||||||||||||||||||||||||||||||||||||||||||||
| 901 | code => 200, | ||||||||||||||||||||||||||||||||||||||||||||||
| 902 | query_string => $qs, | ||||||||||||||||||||||||||||||||||||||||||||||
| 903 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||
| 906 | # *_set_env = \&Apache2::SSI::_set_env; | ||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # This is different from the env() method. This one is obviously private | ||||||||||||||||||||||||||||||||||||||||||||||
| 908 | # whereas the env() one has triggers that could otherwise create an infinite loop. | ||||||||||||||||||||||||||||||||||||||||||||||
| 909 | sub _set_env | ||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 234 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_env: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 234 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 912 | 234 | my $name = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 913 | 234 | ▶ | return( $self->error( "No environment variable name provided." ) ) if( !length( $name ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 234 | ▶ | $self->{_env} = {} if( !ref( $self->{_env} ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 234 | my $env = $self->{_env}; | |||||||||||||||||||||||||||||||||||||||||||||
| 916 | 234 | my $r = $self->apache_request; | |||||||||||||||||||||||||||||||||||||||||||||
| 917 | 234 | ▶ | if( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 918 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 234 | my $v = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 920 | 234 | ▶ | $r->subprocess_env( $name => $v ) if( $r ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 234 | $env->{ $name } = $v; | |||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 234 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||||||
| 926 | sub _trim_trailing_slash | ||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trim_trailing_slash: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | my $uri = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | return( $self->error( "No uri provided to trim trailing slash." ) ) if( !length( "$uri" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | ▶ | unless( Scalar::Util::blessed( $uri ) && $uri->isa( 'URI' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($uri) and $uri->isa("URI")
MC/DC0%0/2
builtin::blessed($uri) and $uri->isa("URI")
builtin::blessed($uri)
$uri->isa("URI")
Truth table0%0/3
A and B
A= builtin::blessed($uri)B= $uri->isa("URI")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 932 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $uri = $self->new_uri( "$uri" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 0 | ▶ | if( substr( $uri->path, -1, 1 ) eq '/' && length( $uri->path ) > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($uri->path, -1, 1) eq "/" and length $uri->path > 1
MC/DC0%0/2
substr($uri->path, -1, 1) eq "/" and length $uri->path > 1
substr($uri->path, -1, 1) eq "/"
length $uri->path > 1
Truth table0%0/3
A and B
A= substr($uri->path, -1, 1) eq "/"B= length $uri->path > 1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 936 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # By splitting the string on '/' and without the last argument for split being -1, perl will remove trailing blank entries | ||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | $uri->path( join( '/', split( '/', $uri->path ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 939 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | return( $uri ); | |||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 944 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 945 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||