develooper Front page | perl.libwww | Postings from November 2001

HTTP::Status shouldn't use @EXPORT

Thread Next
From:
Blair Zajac
Date:
November 12, 2001 14:34
Subject:
HTTP::Status shouldn't use @EXPORT
Message ID:
3BF04E4D.6F69903F@orcaware.com
I'd like to suggest that HTTP::Status no longer use @EXPORT to export the
following subroutines:

	@EXPORT = qw(is_info is_success is_redirect is_error status_message);

for the following reason.  I spent several hours tracking this down.

I ran into the following problem demonstrated by the following code:

	use strict;
	use HTTP::Response;

	package A;

	use HTTP::Status;
	use vars qw(@ISA);

	@ISA = qw(HTTP::Response);

	package main;

	my $a = HTTP::Response->new(200);
	my $b = A->new(200);

	print $a->is_success ? 1 : 0, "\n";
	print $b->is_success ? 1 : 0, "\n";

If you comment out or leave the line

	use HTTP::Status;

then you'll get different output.  If you leave it in, then the result is

	0
	1

and if you take it out, then you get

	1
	1

as you would expect.

I have a code that subclasses from HTTP::Response and calls

	$self->is_success

and if you do as most authors do,

	use HTTP::Status;

without thinking, then without knowing it, your package gets is_success
defined in it.  Then calling

	$self->is_success

is really

	HTTP::Status::is_success($self);

which not what is expected and won't return true even if $self->code is
200.

Best,
Blair

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About