in reply to br tag in CGI.pm V2.91

I don't think you are missing something, it looks like it really is a bug (or at least an oversight). The code that generates this html looks like this (this is the end of a sub generated by _make_tag_func which is called by AUTOLOAD in CGI.pm):

return $XHTML?"\L<br\E$attr />":"\L<br\E$attr>" unless @_; my($tag,$untag) = ("\L<br\E$attr>","\L</br>\E"); my @result = map { "$tag$_$untag" } (ref($rest[0]) eq 'ARRAY') ? @{$rest[0]} : "@rest"; return "@result";

It seems that the intention of this is generate a container-style tag if given arguments, and a standalone tag without arguments. The oversight is that if you call it as an object method it doesn't deal with the fact that the object is at $_[0]. So you end up with this effect:

#!/usr/bin/perl -w ################## use CGI qw/:standard/; print "foo".br()."\n"; my $q = new CGI; print "foo".$q->br()."\n"; __END__ foo<br /> Use of uninitialized value in join or string at (eval 2) line 15. foo<br></br>

That uninitialized value warning comes from the generated sub above. I think the moral is that nobody ever expected the html generating functions to be called as object methods, and it should work fine if you import them with :html and call them as regular subs.


We're not surrounded, we're in a target-rich environment!