rewrite of flow control in Intro.pod
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request.pm
index e2f691f..ded852a 100644 (file)
@@ -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<GET>, C<POST>, C<HEAD>, 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');
@@ -236,7 +264,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];