perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [mp2] one more pass on mp2/apr read() functions
Date Tue, 08 Jun 2004 14:37:52 GMT
I'm doing yet another tweak on the read() API to make things really consistent:

So now we (will) have the following read functions:

- APR::Socket:

$len = $socket->read(my $buffer);

- APR::Bucket:

$len = $bucket->read(my $buffer);

- APR::Filter:

$len = $filter->read(my $buffer);

(plus all the optional arguments as before)

as you can see they now all function indentically and they are much easier to 
use, even though you pass $buffer by reference.

The last change required you to write this kind of code (not very suitable for 
conditionals)

  my $buffer = $x->read();
  if (length $buffer) {
      ...
  }

sure you could do

  if (length(my $buffer = $x->read()) {
      ...
  }

but the problem is that most people will forget the length() part, since most 
of the time it'll work without it. But once you get "0" returned that will 
suddently fail.

So using the new API, you just write:

  if ($x->read(my $buffer)) { ... }

or:

  while($x->read(my $buffer)) { ... }

similar to how streaming filter idiom works:

while ($filter->read(my $buffer)) { $filter->print(lc $buffer) }

I think one more function that needs to be changed is APR::Brigade::flatten, 
since it's really a read() function. So I propose:

   $len = $bb->flatten(my $buffer, ...);

What do you think?



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message