Apache2-SSI
view release on metacpan or search on metacpan
lib/Apache2/SSI/URI.pm view on Meta::CPAN
}
else
{
if( @_ )
{
$self->{path_info} = shift( @_ );
$self->_set_env( PATH_INFO => $self->{path_info} );
$self->{_uri_reset} = 'path_info' unless( $caller eq "${class}\::document_uri" );
}
return( $self->{path_info} );
}
}
sub query_string
{
my $self = shift( @_ );
my $class = ref( $self );
my $caller = (caller(1))[3] // '';
# my $caller = substr( $sub, rindex( $sub, ':' ) + 1 );
my $r = $self->apache_request;
if( $r )
{
if( @_ )
{
my $qs = shift( @_ );
$r->args( $qs );
$self->_set_env( QUERY_STRING => $qs );
$self->{_uri_reset} = 'query_string' unless( $caller eq "${class}\::document_uri" );
}
return( $r->args );
}
else
{
if( @_ )
{
$self->{query_string} = shift( @_ );
$self->_set_env( QUERY_STRING => $self->{query_string} );
$self->{_uri_reset} = 'query_string' unless( $caller eq "${class}\::document_uri" );
}
return( $self->{query_string} );
}
}
sub root
{
my $self = shift( @_ );
return( $self->{root} ) if( $self->{root} );
my $hash =
{
code => 200,
document_uri => $self->new_uri( '/' ),
document_root => $self->document_root,
debug => $self->debug,
path_info => '',
query_string => '',
_path_info_processed => 1,
};
$hash->{document_path} = $hash->{document_uri};
$hash->{apache_request} = $self->apache_request if( $self->apache_request );
my $root = bless( $hash => ref( $self ) );
# Scalar::Util::weaken( $copy );
$root->{base_dir} = $root;
$root->{base_uri} = $root;
$self->{root} = $root;
return( $root );
}
# shortcut
sub uri { return( shift->document_uri( @_ ) ); }
# Path info works as a path added to a document uri, such as:
# /my/doc.html/path/info
# But we need to distinguish with missing document hierarchy inside a directory, such as:
# /my/folder/missing_doc.html/path/info
# otherwise we would be treating /missing_doc.html/path/info as a path info
sub _find_path_info
{
my $self = shift( @_ );
my( $uri_path, $doc_root ) = @_;
$doc_root //= $self->document_root;
my $qs = '';
my $sep = $DIR_SEP;
$sep = '/' if( !length( $sep ) );
if( Scalar::Util::blessed( $uri_path ) && $uri_path->isa( 'URI::file' ) )
{
$uri_path = $uri_path->file;
}
my $u = $self->collapse_dots( $uri_path );
$qs = $u->query;
$uri_path = $u->path;
# Pass the OS to ensure we get ./ss/include.cgi becomes .\ssi\include.cgi
my $path = URI::file->new( $uri_path )->file( $^O );
$doc_root = $doc_root->file( $^O ) if( Scalar::Util::blessed( $doc_root ) && $doc_root->isa( 'URI::file' ) );
$doc_root = substr( $doc_root, 0, length( $doc_root ) - length( $sep ) ) if( substr( $doc_root, -length( $sep ), length( $sep ) ) eq $sep );
return( $self->error( "URI path must be an absolute path starting with '/'. Path provided was \"$uri_path\"." ) ) if( substr( $uri_path, 0, 1 ) ne '/' );
# No need to go further
if( -e( "${doc_root}${path}" ) )
{
return({
filepath => "${doc_root}${path}",
path => $uri_path,
query_string => $qs,
code => 200,
});
}
elsif( $uri_path eq '/' )
{
return({
filepath => $doc_root,
path => $uri_path,
path_info => undef(),
query_string => $qs,
code => ( -e( $doc_root ) ? 200 : 404 ),
});
}
my @parts = split( '/', substr( $uri_path, 1 ) );
my $trypath = '';
my $trypath_uri = '';
my $pathinfo = '';
foreach my $p ( @parts )
{
( run in 1.425 second using v1.01-cache-2.11-cpan-d8267643d1d )