X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=66112554305ab8ffb663b1d488661202e7dbb123;hb=822fe9544767709e6d75eda2b0cbcfb46bb494dd;hp=dd1f312ef22abf329c48dd58877469e18e1ed5b6;hpb=b4ca0ee8572ea5c33295686b7f786ab5ff43a2b7;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index dd1f312..6611255 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -38,6 +38,7 @@ Catalyst::Request - Catalyst Request Class $req->content_encoding; $req->content_length; $req->content_type; + $req->cookie; $req->cookies; $req->header; $req->headers; @@ -117,6 +118,34 @@ Shortcut to $req->headers->content_length Shortcut to $req->headers->content_type +=item $req->cookie + +A convenient method to $req->cookies. + + $cookie = $c->request->cookie('name'); + @cookies = $c->request->cookie; + +=cut + +sub cookie { + my $self = shift; + + if ( @_ == 0 ) { + return keys %{ $self->cookies }; + } + + if ( @_ == 1 ) { + + my $name = shift; + + unless ( exists $self->cookies->{$name} ) { + return undef; + } + + return $self->cookies->{$name}; + } +} + =item $req->cookies Returns a reference to a hash containing the cookies. @@ -144,12 +173,12 @@ Lookup the current users DNS hostname. sub hostname { my $self = shift; - if ( @_ ) { - $self->{hostname} = shift; + if ( @_ == 0 && not $self->{hostname} ) { + $self->{hostname} = gethostbyaddr( inet_aton( $self->address ), AF_INET ); } - unless ( $self->{hostname} ) { - $self->{hostname} = gethostbyaddr( inet_aton( $self->address ), AF_INET ); + if ( @_ == 1 ) { + $self->{hostname} = shift; } return $self->{hostname}; @@ -161,8 +190,8 @@ Shortcut for $req->body. =item $req->match -This contains be the matching part of a regexp action. otherwise it -returns the same as 'action'. +This contains the matching part of a regexp action. Otherwise +it returns the same as 'action'. print $c->request->match; @@ -174,7 +203,8 @@ Contains the request method (C, C, C, etc). =item $req->param -Get request parameters with a CGI.pm like param method. +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'); @@ -235,7 +265,7 @@ Shortcut for $req->parameters. =item $req->parameters Returns a reference to a hash containing parameters. Values can -be either a scalar or a arrayref containing scalars. +be either a scalar or an arrayref containing scalars. print $c->request->parameters->{field}; print $c->request->parameters->{field}->[0];