X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=d5cb9ed74aef8e6c8c988d36a316aadd91753a3a;hb=a82c2894ea88511dd690442cb58d33d7a62cecf8;hp=3aaa6aff85485748006c84b906dde9ccd61a2f7d;hpb=fbcc39ad23f2bbecf5d84c9ba581e6af86fcd460;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 3aaa6af..d5cb9ed 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -6,7 +6,7 @@ use base 'Class::Accessor::Fast'; use IO::Socket qw[AF_INET inet_aton]; __PACKAGE__->mk_accessors( - qw/action address arguments base cookies handle headers match method + qw/action address arguments cookies headers match method protocol query_parameters secure snippets uri user/ ); @@ -44,7 +44,6 @@ Catalyst::Request - Catalyst Request Class $req->content_type; $req->cookie; $req->cookies; - $req->handle; $req->header; $req->headers; $req->hostname; @@ -102,9 +101,40 @@ Returns a reference to an array containing the arguments. 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 the string C +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 +then C is C. + +=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 @@ -128,6 +158,8 @@ be either a scalar or an arrayref containing scalars. 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 @@ -188,9 +220,8 @@ Returns a reference to a hash containing the cookies. print $c->request->cookies->{mycookie}->value; -=item $req->handle - -Request IO handle. +The cookies in the hash are indexed by name, and the values are C +objects. =item $req->header @@ -247,10 +278,19 @@ Contains the request method (C, C, C, etc). Get request parameters with a CGI.pm-compatible param method. This is a method for accessing parameters in $c->req->parameters. - $value = $c->request->param('foo'); - @values = $c->request->param('foo'); + $value = $c->request->param( 'foo' ); + @values = $c->request->param( 'foo' ); @params = $c->request->param; +Like C, and B previous versions of Catalyst, passing multiple +arguments to this method, like this: + + $c->request( 'foo', 'bar', 'gorch', 'quxx' ); + +will set the parameter C to the multiple values C, C and +C. Previously this would have added C as another value to C +(creating it if it didn't exist before), and C as another value for C. + =cut sub param { @@ -279,23 +319,9 @@ sub param { : $self->parameters->{$param}; } } - - if ( @_ > 1 ) { - - while ( my ( $field, $value ) = splice( @_, 0, 2 ) ) { - - next unless defined $field; - - if ( exists $self->parameters->{$field} ) { - for ( $self->parameters->{$field} ) { - $_ = [$_] unless ref($_) eq "ARRAY"; - push( @$_, $value ); - } - } - else { - $self->parameters->{$field} = $value; - } - } + elsif ( @_ > 1 ) { + my $field = shift; + $self->parameters->{$field} = [@_]; } } @@ -311,6 +337,8 @@ be either a scalar or an arrayref containing scalars. print $c->request->parameters->{field}; print $c->request->parameters->{field}->[0]; +This is the combination of C and C. + =cut sub parameters { @@ -334,19 +362,21 @@ alias for path, added for compability with L sub path { my ( $self, $params ) = @_; - - if ( $params ) { - # base must always have a trailing slash - $params .= '/' unless ( $params =~ /\/$/ ); - $self->uri->path( $params ); + + if ($params) { + $self->uri->path($params); + } + else { + return $self->{path} if $self->{path}; } - my $path = $self->uri->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; } @@ -361,6 +391,9 @@ be either a scalar or an arrayref containing scalars. 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] ) @@ -380,7 +413,7 @@ Shortcut to $req->headers->referer. Referring page. =item $req->secure -Contains a boolean whether the communciation is secure. +Contains a boolean denoting whether the communication is secure. =item $req->snippets