summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-11-05 16:25:26 +0100
committerfranck cuny <franck@lumberjaph.net>2010-11-05 16:25:26 +0100
commitfbe0876e7c8ab998a08e1eac6e7e72d92edeac10 (patch)
tree11a6fb1cddbc31134981cf8f0872f9e3cc674cab
parenttypo (diff)
downloadnet-http-spore-fbe0876e7c8ab998a08e1eac6e7e72d92edeac10.tar.gz
remove two methods
-rw-r--r--Changes5
-rw-r--r--lib/Net/HTTP/Spore/Request.pm136
-rw-r--r--t/spore-request/path_info.t27
-rw-r--r--t/spore-request/query_string.t25
4 files changed, 61 insertions, 132 deletions
diff --git a/Changes b/Changes
index f1ce76b..58c08be 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+0.03 
+
+    - remove 'path_info' method from N::H::S::Request object
+    - remove 'query_string' method from N::H::S::Request object
+
 0.02 Thu 14 Oct 2010 02:08:27 PM CEST  
     - add types for JSON booleans values
     - params is now an hashref with 'optional' and 'required'
diff --git a/lib/Net/HTTP/Spore/Request.pm b/lib/Net/HTTP/Spore/Request.pm
index 8a42e16..5b1caa2 100644
--- a/lib/Net/HTTP/Spore/Request.pm
+++ b/lib/Net/HTTP/Spore/Request.pm
@@ -128,53 +128,40 @@ sub body {
     }
 }
 
+sub base {
+    my $self = shift;
+    URI->new( $self->_uri_base )->canonical;
+}
+
 sub input   { (shift)->body(@_) }
 sub content { (shift)->body(@_) }
 sub secure  { $_[0]->scheme eq 'https' }
 
-# stolen from HTTP::Request::Common
-sub _boundary {
-    my ( $self, $size ) = @_;
+# TODO
+# need to refactor this method, with path_info and query_string construction
+sub uri {
+    my ($self, $path_info, $query_string) = @_;
 
-    return "xYzZy" unless $size;
+    if ( !defined $path_info || !defined $query_string ) {
+        my @path_info = $self->_path;
+        $path_info    = $path_info[0] if !$path_info;
+        $query_string = $path_info[1] if !$query_string;
+    }
 
-    my $b =
-      MIME::Base64::encode( join( "", map chr( rand(256) ), 1 .. $size * 3 ),
-        "" );
-    $b =~ s/[\W]/X/g;
-    return $b;
-}
+    my $base = $self->_uri_base;
 
-sub _form_data {
-    my ( $self, $data ) = @_;
+    my $path_escape_class = '^A-Za-z0-9\-\._~/';
 
-    my $form_data;
-    foreach my $k ( keys %$data ) {
-        push @$form_data,
-            'Content-Disposition: form-data; name="' 
-          . $k
-          . '"'."\r\n\r\n"
-          . $data->{$k};
-    }
+    my $path = URI::Escape::uri_escape($path_info || '', $path_escape_class);
 
-    my $b = $self->_boundary(10);
-    my $t = [];
-    foreach (@$form_data) {
-        push @$t, '--', $b, "\r\n", $_, "\r\n";
+    if (defined $query_string && length($query_string) > 0) {
+        $path .= '?' . $query_string;
     }
-    push @$t, '--', $b, , '--', "\r\n";
-    my $content = join("", @$t);
-    return ($content, $b);
-}
 
-# TODO
-sub path_info {
-    my $self = shift;
-    my ($path) = $self->_path;
-    $path;
+    $base =~ s!/$!! if $path =~ m!^/!;
+    return URI->new( $base . $path )->canonical;
 }
 
-# TODO
 sub _path {
     my $self = shift;
 
@@ -200,52 +187,6 @@ sub _path {
     return ( $path, $query_string );
 }
 
-# TODO
-sub query_string {
-    my $self = shift;
-    my ( undef, $query_string ) = $self->_path;
-    $query_string;
-}
-
-# TODO
-sub uri {
-    my $self = shift;
-
-    my $path_info    = shift;
-    my $query_string = shift;
-
-    if ( !defined $path_info || !defined $query_string ) {
-        my @path_info = $self->_path;
-        $path_info    = $path_info[0] if !$path_info;
-        $query_string = $path_info[1] if !$query_string;
-    }
-
-    my $base = $self->_uri_base;
-
-    my $path_escape_class = '^A-Za-z0-9\-\._~/';
-
-    my $path = URI::Escape::uri_escape($path_info || '', $path_escape_class);
-
-    if (defined $query_string && length($query_string) > 0) {
-        $path .= '?' . $query_string;
-    }
-
-    $base =~ s!/$!! if $path =~ m!^/!;
-    return URI->new( $base . $path )->canonical;
-}
-
-# TODO retourner les query parameters ? vu qu'on a pas encore peuple l'url, on gere comment ?
-sub query_parameters {
-    my $self = shift;
-}
-
-# TODO
-sub base {
-    my $self = shift;
-    URI->new( $self->_uri_base )->canonical;
-}
-
-# TODO
 sub _uri_base {
     my $self = shift;
     my $env  = $self->env;
@@ -260,6 +201,41 @@ sub _uri_base {
     return $uri;
 }
 
+# stolen from HTTP::Request::Common
+sub _boundary {
+    my ( $self, $size ) = @_;
+
+    return "xYzZy" unless $size;
+
+    my $b =
+      MIME::Base64::encode( join( "", map chr( rand(256) ), 1 .. $size * 3 ),
+        "" );
+    $b =~ s/[\W]/X/g;
+    return $b;
+}
+
+sub _form_data {
+    my ( $self, $data ) = @_;
+
+    my $form_data;
+    foreach my $k ( keys %$data ) {
+        push @$form_data,
+            'Content-Disposition: form-data; name="' 
+          . $k
+          . '"'."\r\n\r\n"
+          . $data->{$k};
+    }
+
+    my $b = $self->_boundary(10);
+    my $t = [];
+    foreach (@$form_data) {
+        push @$t, '--', $b, "\r\n", $_, "\r\n";
+    }
+    push @$t, '--', $b, , '--', "\r\n";
+    my $content = join("", @$t);
+    return ($content, $b);
+}
+
 sub new_response {
     my $self = shift;
     my $res = Net::HTTP::Spore::Response->new(@_);
diff --git a/t/spore-request/path_info.t b/t/spore-request/path_info.t
deleted file mode 100644
index 17645af..0000000
--- a/t/spore-request/path_info.t
+++ /dev/null
@@ -1,27 +0,0 @@
-use strict;
-use Test::More;
-
-use Net::HTTP::Spore::Request;
-
-my $env = {
-    REQUEST_METHOD  => 'GET',
-    SERVER_NAME     => 'localhost',
-    SERVER_PORT     => '80',
-    SCRIPT_NAME     => '',
-    PATH_INFO       => '/:database/:key',
-    REQUEST_URI     => '',
-    QUERY_STRING    => '',
-    SERVER_PROTOCOL => 'HTTP/1.0',
-    'spore.params'  => [qw/database test_spore key foo/],
-};
-
-ok my $request = Net::HTTP::Spore::Request->new($env);
-
-is $request->path_info, '/test_spore/foo';
-
-$env->{'spore.params'} = [qw/database test_spore key foo another key/];
-is $request->path_info, '/test_spore/foo';
-
-is $request->path, '/test_spore/foo';
-
-done_testing;
diff --git a/t/spore-request/query_string.t b/t/spore-request/query_string.t
deleted file mode 100644
index 2ee7979..0000000
--- a/t/spore-request/query_string.t
+++ /dev/null
@@ -1,25 +0,0 @@
-use strict;
-use Test::More;
-
-use Net::HTTP::Spore::Request;
-
-my $env = {
-    REQUEST_METHOD  => 'GET',
-    SERVER_NAME     => 'localhost',
-    SERVER_PORT     => '80',
-    SCRIPT_NAME     => '',
-    PATH_INFO       => '/:database',
-    REQUEST_URI     => '',
-    QUERY_STRING    => '',
-    SERVER_PROTOCOL => 'HTTP/1.0',
-    'spore.params'  => [qw/database test_spore key foo rev 123/],
-};
-
-ok my $request = Net::HTTP::Spore::Request->new($env);
-
-is $request->query_string, 'key=foo&rev=123';
-
-$env->{PATH_INFO} = '/:database/:key';
-is $request->query_string, 'rev=123';
-
-done_testing;