X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=fe05db7ea12dfeee914b679adbb968765cd73595;hb=3882a476f19a3c4190a755367c45c9cf5dc2e16c;hp=e2f691fab49ed100a631a164606078af36cbd3dc;hpb=993862744fe3f35dc8f3afc7741e25341630e69c;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index e2f691f..fe05db7 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -117,6 +117,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->cookie }; + } + + if ( @_ == 1 ) { + + my $name = shift; + + unless ( exists $self->cookie->{$name} ) { + return undef; + } + + return $self->cookie->{$name}; + } +} + =item $req->cookies Returns a reference to a hash containing the cookies. @@ -144,13 +172,12 @@ Lookup the current users DNS hostname. sub hostname { my $self = shift; - if ( @_ ) { - $self->{hostname} = shift; - return $self->{hostname}; + 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}; @@ -162,8 +189,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; @@ -175,7 +202,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');