>
> =head2 $req->path
>
Returns the path, i.e. the part of the URI after $req->base, for the
> current request.
Pasted below is Catalyst::Request's path method. Note from the final else
block that $req->path returns the request uri's path ($req->uri->path) with
the $req->base->path *removed* as the documentation says.
So, if the request URI and base URI are these:
http://localhost/myapp/path/to/action # $req->uri
http://localhost/myapp/ # $req->base
then $req->path is:
path/to/action
Using the example above, and looking at what $req->path( ) does as a setter:
$req->path( $req->path );
would result in a new request URI of:
http://localhost/path/to/action.
The path method doesn't document what it does as a setter, but this
behavior looks broken because it alters the request URI's path.
What do you think?
sub path {
my ( $self, @params ) = @_;
if (@params) {
$self->uri->path(@params);
$self->_clear_path;
}
elsif ( $self->_has_path ) {
return $self->_path;
}
else {
my $path = $self->uri->path;
my $location = $self->base->path;
$path =~ s/^(\Q$location\E)?//;
$path =~ s/^\///;
$self->_path($path);
return $path;
}
}
--
Bill Moseley
moseley@hank.org
> =head2 $req->path
>
Returns the path, i.e. the part of the URI after $req->base, for the
> current request.
Pasted below is Catalyst::Request's path method. Note from the final else
block that $req->path returns the request uri's path ($req->uri->path) with
the $req->base->path *removed* as the documentation says.
So, if the request URI and base URI are these:
http://localhost/myapp/path/to/action # $req->uri
http://localhost/myapp/ # $req->base
then $req->path is:
path/to/action
Using the example above, and looking at what $req->path( ) does as a setter:
$req->path( $req->path );
would result in a new request URI of:
http://localhost/path/to/action.
The path method doesn't document what it does as a setter, but this
behavior looks broken because it alters the request URI's path.
What do you think?
sub path {
my ( $self, @params ) = @_;
if (@params) {
$self->uri->path(@params);
$self->_clear_path;
}
elsif ( $self->_has_path ) {
return $self->_path;
}
else {
my $path = $self->uri->path;
my $location = $self->base->path;
$path =~ s/^(\Q$location\E)?//;
$path =~ s/^\///;
$self->_path($path);
return $path;
}
}
--
Bill Moseley
moseley@hank.org