[Catalyst] Base URI breakdown

Andrew Rodland arodland at comcast.net
Sat Mar 7 03:25:42 GMT 2009


On Friday 06 March 2009 09:02:01 pm Trevor Phillips wrote:
> In a Catalyst app, I need to break down the base request URL to
> extract hostname, port, etc separately.
>
> I could do this with a regexp on $c->request->base, or I could use the
> URI perl lib, but is there already a way to access this within
> Catalyst?
>
> The docs say that $c->request->base is a string only, whereas I'd like
> to access separately bits like $c->request->base->host and
> $c->request->base->port.

$c->req->base is a URI object under all of the Engine types that I'm aware of. 
The docs don't promise this, but they don't say it's not either. Anyway 
there's no reason you couldn't do URI->new($c->req->base) which will be a 
perfectly good URI object whether base is a URI or an unblessed string. :)

Andrew



More information about the Catalyst mailing list