X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=41f8d8d04024d94bf0231fd1e933a22e70080390;hb=db046247b008e64c5625b3a52570015826b8a0ee;hp=09741abb441d09a3d854caf46bbb7aeafcbc73dd;hpb=8fbcd90cdb30aed53d22d1cdbad95880f1c11693;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 09741ab..41f8d8d 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -5,7 +5,7 @@ use base 'Class::Accessor::Fast'; __PACKAGE__->mk_accessors( qw/action address arguments body base cookies headers hostname match - method parameters path snippets uploads/ + method parameters path protocol secure snippets uploads user/ ); *args = \&arguments; @@ -33,8 +33,6 @@ Catalyst::Request - Catalyst Request Class $req->arguments; $req->base; $req->body; - $req->body_length; - $req->body_ref; $req->content_encoding; $req->content_length; $req->content_type; @@ -49,11 +47,15 @@ Catalyst::Request - Catalyst Request Class $req->params; $req->parameters; $req->path; + $req->protocol; $req->referer; + $req->secure; $req->snippets; $req->upload; $req->uploads; - $req->user_agent + $req->uri; + $req->user; + $req->user_agent; See also L. @@ -101,34 +103,6 @@ C or C. print $c->request->body -=item $req->body_length - -Returns the length of body in bytes. - - print $c->request->body_length - -=cut - -sub body_length { - my $self = shift; - - use bytes; - - return 0 unless $self->body; - return length($self->body); -} - -=item $req->body_ref - -Returns a reference to body. - -=cut - -sub body_ref { - my $self = shift; - return \$self->{body}; -} - =item $req->content_encoding Shortcut to $req->headers->content_encoding @@ -197,22 +171,6 @@ sub param { return keys %{ $self->parameters }; } - if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) { - - while ( my ( $field, $value ) = splice( @{ $_[0] }, 0, 2 ) ) { - - if ( exists $self->parameters->{$field} ) { - for ( $self->parameters->{$field} ) { - $_ = [$_] unless ref($_) eq "ARRAY"; - push( @$_, $value ); - } - } - else { - $self->parameters->{$field} = $value; - } - } - } - if ( @_ == 1 ) { my $param = shift; @@ -231,7 +189,25 @@ sub param { ? ( $self->parameters->{$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; + } + } + } } =item $req->params @@ -252,10 +228,18 @@ Contains the path. print $c->request->path; +=item $req->protocol + +Contains the protocol. + =item $req->referer Shortcut to $req->headers->referer. Referring page. +=item $req->secure + +Contains a boolean whether the communciation is secure. + =item $req->snippets Returns a reference to an array containing regex snippets. @@ -283,22 +267,6 @@ sub upload { return keys %{ $self->uploads }; } - if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) { - - while ( my ( $field, $upload ) = splice( @{ $_[0] }, 0, 2 ) ) { - - if ( exists $self->uploads->{$field} ) { - for ( $self->uploads->{$field} ) { - $_ = [$_] unless ref($_) eq "ARRAY"; - push( @$_, $upload ); - } - } - else { - $self->uploads->{$field} = $upload; - } - } - } - if ( @_ == 1 ) { my $upload = shift; @@ -318,6 +286,22 @@ sub upload { : $self->uploads->{$upload}; } } + + if ( @_ > 1 ) { + + while ( my ( $field, $upload ) = splice( @_, 0, 2 ) ) { + + if ( exists $self->uploads->{$field} ) { + for ( $self->uploads->{$field} ) { + $_ = [$_] unless ref($_) eq "ARRAY"; + push( @$_, $upload ); + } + } + else { + $self->uploads->{$field} = $upload; + } + } + } } =item $req->uploads @@ -328,6 +312,22 @@ hashref or a arrayref containing C objects. my $upload = $c->request->uploads->{field}; my $upload = $c->request->uploads->{field}->[0]; +=item $req->uri + +Shortcut for C<< $req->base . $req->path >>. + +=cut + +sub uri { + my $self = shift; + my $path = shift || $self->path || ''; + return $self->base . $path; +} + +=item $req->user + +Contains the user name of user if authentication check was successful. + =item $req->user_agent Shortcut to $req->headers->user_agent. User Agent version string.