Re: [mp2] return value of print can break legacy apps

[prev] [thread] [next] [Date index for 2004/12/10]

From: Stas Bekman
Subject: Re: [mp2] return value of print can break legacy apps
Date: 15:58 on 10 Dec 2004
Tuomo Salo wrote:
> Under mod_perl2 the return value of print seems to be the number of
> bytes printed. I run across a legacy app (a registry script), that
> frequently used the following idiom:
[...]
> This behaviour is nearly impossible to notice, since the redirection
> will happen as usual. The resulting malfunctions are not trivial to
> debug, since the error results from two un(der)documented features,
> and the symptoms can be completely random.
[...]
> However, this could be a thing worth mentioning in a "possible pitfalls"
> document.

Frankly I'm not sure what's the best solution here. We could make it 
return success and failure, but it will break consistency with other 
methods. Observe that the following methods all behave similarly:

http://perl.apache.org/docs/2.0/api/Apache/RequestIO.html#C_print_
http://perl.apache.org/docs/2.0/api/Apache/RequestIO.html#C_puts_
http://perl.apache.org/docs/2.0/api/Apache/RequestIO.html#C_printf_
http://perl.apache.org/docs/2.0/api/Apache/Filter.html#C_print_
http://perl.apache.org/docs/2.0/api/APR/Socket.html#C_send_

same goes for read() and recv()

http://perl.apache.org/docs/2.0/api/Apache/RequestIO.html#C_read_
http://perl.apache.org/docs/2.0/api/Apache/Filter.html#C_read_
http://perl.apache.org/docs/2.0/api/APR/Socket.html#C_recv_

I suppose in the case of CGI.pm the solution is very simple, fix the 
modperl case further to return success if 0 or more bytes returned (I can 
write a patch for CGI.pm unless you want to do that). Notice that mp2's 
print() croaks on failure (like most other mp2 methods) whereas perl's 
print() will silently fail. So the modperl's behavior is better if you ask 
me, since 99.999% users don't check the return value of print call.

Of course I'd prefer to document this in "possible pitfalls", but let's 
hear what others think.

As we plan to post mp2-RC1 now, there is not much time left for API changes.

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

(message missing)

Re: [mp2] return value of print can break legacy apps
Stas Bekman 15:58 on 10 Dec 2004

Generated at 11:26 on 21 Dec 2004 by mariachi v0.52