[Catalyst] Catalyst::Request path method as a setter

John Napiorkowski jjn1056 at yahoo.com
Mon Oct 21 16:13:48 GMT 2013


My guess here is that path should be RO and that if you need to write code =
that messed with the path, that should happen in plack middleware.

I'll ask around IRC to try and find out why this was allowed in the first p=
lace. =A0My guess it that we wanted to allow people to change the path for =
doing complex path rewriting.

jnap



On Monday, October 21, 2013 10:00 AM, Bill Moseley <moseley at hank.org> wrote:
 =

=3Dhead2 $req->path
>
=A0
Returns the path, i.e. the part of the URI after $req->base, for the curren=
t request.

Pasted below is Catalyst::Request's path method. =A0 Note from the final el=
se block that $req->path returns the request uri's path ($req->uri->path) w=
ith the $req->base->path removed=A0as the documentation says.

So, if the request URI and base URI are these:

http://localhost/myapp/path/to/action =A0# $req->uri
http://localhost/myapp/ =A0# $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 behavio=
r looks broken because it alters the request URI's path.

What do you think?


sub path {
=A0 =A0 my ( $self, @params ) =3D @_;

=A0 =A0 if (@params) {
=A0 =A0 =A0 =A0 $self->uri->path(@params);
=A0 =A0 =A0 =A0 $self->_clear_path;
=A0 =A0 }
=A0 =A0 elsif ( $self->_has_path ) {
=A0 =A0 =A0 =A0 return $self->_path;
=A0 =A0 }
=A0 =A0 else {
=A0 =A0 =A0 =A0 my $path =A0 =A0 =3D $self->uri->path;
=A0 =A0 =A0 =A0 my $location =3D $self->base->path;
=A0 =A0 =A0 =A0 $path =3D~ s/^(\Q$location\E)?//;
=A0 =A0 =A0 =A0 $path =3D~ s/^\///;
=A0 =A0 =A0 =A0 $self->_path($path);

=A0 =A0 =A0 =A0 return $path;
=A0 =A0 }
}




-- =

Bill Moseley
moseley at hank.org =

_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20131021/e2170=
e77/attachment.htm


More information about the Catalyst mailing list