added $c->req->full_uri method (core from C::P::RequireSSL: thanks andyg!)
Jesse Sheidlower [Sat, 17 Sep 2005 01:17:54 +0000 (01:17 +0000)]
Changes
lib/Catalyst/Request.pm

diff --git a/Changes b/Changes
index 3e0539a..4f62181 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Catalyst.
 
 5.34  2005-08-21 00:00:00
         - Fixed mkpath in Catalyst::Helper (Autrijus Tang)
+        - added $c->req->full_uri method (Jesse Sheidlower)
 
 5.33  2005-08-10 15:25:00
        - Now with updated manifest.
index 6611255..e7ce1f1 100644 (file)
@@ -40,6 +40,7 @@ Catalyst::Request - Catalyst Request Class
     $req->content_type;
     $req->cookie;
     $req->cookies;
+    $req->full_uri;
     $req->header;
     $req->headers;
     $req->hostname;
@@ -152,6 +153,32 @@ Returns a reference to a hash containing the cookies.
 
     print $c->request->cookies->{mycookie}->value;
 
+=item $req->full_uri
+
+Returns the complete URI, with the parameter query string.
+
+=cut
+
+sub full_uri {
+  my $self = shift;
+  my $uri = $self->uri;
+  my $full_uri = $uri;
+
+  if ( scalar $self->param ) {
+    my @params;
+    foreach my $arg ( sort keys %{ $self->params } ) {
+      if ( ref $self->params->{$arg} ) {
+        my $list = $self->params->{$arg};
+        push @params, map { "$arg=" . $_  } sort @{$list};
+      } else {
+        push @params, "$arg=" . $self->params->{$arg};
+      }
+    }
+    $full_uri .= '?' . join( '&', @params );
+  }       
+  return $full_uri;
+}
+
 =item $req->header
 
 Shortcut to $req->headers->header