Permalink
Browse files

remove two methods

  • Loading branch information...
1 parent 33cb473 commit fbe0876e7c8ab998a08e1eac6e7e72d92edeac10 @franckcuny franckcuny committed Nov 5, 2010
Showing with 61 additions and 132 deletions.
  1. +5 −0 Changes
  2. +56 −80 lib/Net/HTTP/Spore/Request.pm
  3. +0 −27 t/spore-request/path_info.t
  4. +0 −25 t/spore-request/query_string.t
View
@@ -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'
@@ -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(@_);
@@ -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;
@@ -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;

0 comments on commit fbe0876

Please sign in to comment.