use IO::Socket qw[AF_INET inet_aton];
__PACKAGE__->mk_accessors(
- qw/action address arguments base cookies headers match method
+ qw/action address arguments cookies headers match method
protocol query_parameters secure snippets uri user/
);
print $c->request->arguments->[0];
+For example, if your action was
+
+ package MyApp::C::Foo;
+
+ sub moose : Local {
+ ...
+ }
+
+And the URI for the request was C<http://.../foo/moose/bah> the string C<bah>
+would be the first and only argument.
+
=item $req->base
-Contains the url base. This will always have a trailing slash.
+Contains the URI base. This will always have a trailing slash.
+
+If your application was queried with the URI C<http://localhost:3000/some/path>
+then C<base> is C<http://localhost:3000/>.
+
+=cut
+
+sub base {
+ my ( $self, $base ) = @_;
+
+ return $self->{base} unless $base;
+
+ $self->{base} = $base;
+
+ # set the value in path for backwards-compat
+ if ( $self->uri ) {
+ $self->path;
+ }
+
+ return $self->{base};
+}
=item $req->body
print $c->request->body_parameters->{field};
print $c->request->body_parameters->{field}->[0];
+
+These are the parameters from the POST part of the request, if any.
=item $req->body_params
print $c->request->cookies->{mycookie}->value;
+The cookies in the hash are indexed by name, and the values are C<CGI::Cookie>
+objects.
+
=item $req->header
Shortcut to $req->headers->header
print $c->request->parameters->{field};
print $c->request->parameters->{field}->[0];
+This is the combination of C<query_parameters> and C<body_parameters>.
+
=cut
sub parameters {
my ( $self, $params ) = @_;
if ($params) {
-
- # base must always have a trailing slash
- $params .= '/' unless ( $params =~ /\/$/ );
$self->uri->path($params);
}
+ else {
+ return $self->{path} if $self->{path};
+ }
my $path = $self->uri->path;
my $location = $self->base->path;
$path =~ s/^(\Q$location\E)?//;
$path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
$path =~ s/^\///;
+ $self->{path} = $path;
return $path;
}
print $c->request->query_parameters->{field};
print $c->request->query_parameters->{field}->[0];
+
+These are the parameters from the query string portion of the request's URI, if
+any.
=item $req->read( [$maxlength] )