Subject: | connect() method returns incorrect value [fix proposed] |
I am using HTTP::Handle v0.2, with the changes suggested in Bug 24144,
on Perl v5.8.0 under Linux 2.4.22.
The pod describes the connect() method as returning undef except on failure.
This is not the case. The successful path through the connect method
does not include an explicit 'return' statement. As a result, the return
value on success is that of the last evaluated expression.
To fix this, I propose including an explicit 'return undef;' statement
as the last line of the connect() method.
The return values from this method are the reverse of most Perl
functions, which return true on success and false, or undef on failure -
But to change this now would break existing code written around this module.
The following code illustrates that the return value on success is not
undefined:
#!/usr/bin/perl
use HTTP::Handle;
my $http = HTTP::Handle->new( uri => "http://www.cpan.org/" );
my $rv = $http->connect();
defined $rv and print "http->connect() return value is not undef\n";
$rv == -1 or print "but its value does not indicate an error\n";
And this is the diff:
--- /tmp/HTTP-Handle/Handle.pm 2004-07-03 08:44:53.000000000 +0000
+++ /usr/lib/perl5/site_perl/5.8.0/HTTP/Handle.pm 2006-12-30
11:18:26.000000000 +0000
@@ -178,6 +179,9 @@
_debug("Redirecting to " .
$self->{"http_response"}->{"Location"});
goto CONNECT;
}
+
+ return undef;
+
}
=pod