Update of /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest
In directory usw-pr-cvs1:/tmp/cvs-serv18530/lib/HTTP/WebTest
Modified Files:
Request.pm
Log Message:
Implemented
Index: Request.pm
===================================================================
RCS file: /cvsroot/http-webtest/HTTP-WebTest/lib/HTTP/WebTest/Request.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Request.pm 4 Jul 2002 22:39:17 -0000 1.1
--- Request.pm 24 Jul 2002 21:15:26 -0000 1.2
***************
*** 62,65 ****
--- 62,70 ----
use base qw(HTTP::Request);
+ use HTTP::Request::Common;
+ use URI;
+
+ use HTTP::WebTest::Utils qw(make_access_method);
+
=head2 base_uri($optional_uri)
***************
*** 73,83 ****
=cut
! sub base_uri {
! }
! =head2 uri
! Method C<uri> is redefined and it is not allowed to be used as setter
! anymore.
=head3 Returns
--- 78,87 ----
=cut
! sub base_uri { shift->SUPER::uri(@_) }
! =head2 uri($optional_uri)
! Method C<uri> is redefined. It is same as C<base_uri> for non-GET
! request. For GET requests it returns URI with query parameters.
=head3 Returns
***************
*** 88,91 ****
--- 92,142 ----
sub uri {
+ my $self = shift;
+
+ if(@_) {
+ $self->base_uri(@_);
+ my $new_uri = $self->base_uri;
+ if(defined $new_uri) {
+ my @params = $new_uri->query_form;
+ $new_uri->query(undef);
+ $self->params(\@params);
+ }
+ }
+
+ my $uri = $self->base_uri;
+
+ $uri->query_form(@{$self->params})
+ if defined($self->method) and $self->method eq 'GET';
+
+ return $uri;
+ }
+
+ *url = \&uri;
+
+ =head2 content_ref
+
+ Method C<content_ref> is redefined. For POST requests it returns POST
+ query content corresponding to query parameters.
+
+ =cut
+
+ sub content_ref {
+ my $self = shift;
+
+ return $self->SUPER::content_ref
+ unless defined($self->method) and $self->method eq 'POST';
+
+ my $req = POST $self->uri, $self->params;
+
+ # DANGER: EVIL HACK
+ for my $header qw(Content-Type Content-Length) {
+ if(defined $header) {
+ $self->header($header => $req->header($header));
+ } else {
+ $self->remove_header($header);
+ }
+ }
+
+ return $req->content_ref;
}
***************
*** 101,106 ****
=cut
! sub params {
! }
=head1 COPYRIGHT
--- 152,156 ----
=cut
! *params = make_access_method('PARAMS', sub { [] });
=head1 COPYRIGHT
|