I'd rather see:
my ($data, $len) = foo(...);
so much more perlish. but I guess it's too late in the game.
The only inconvenience is that you can't use that in the while loop:
while (defined my $len = foo($data, ...) {}
there is no problem here. flatten should accept how much data to read as an argument and return how much it actually read as a return value. That's exactly how perl's read() works. and that value is optional.
the problem with all of these is that it's breaking away from the 1:1 mapping of the original apr_brigade_(p)flatten APIs. if we're going to do that to make them more perlish, I'd much rather see
my $data = $bb->flatten(30); # calls apr_brigade_flatten my $data = $bb->flatten($p); # calls apr_brigade_pflatten
and throw away the length component, since it's very rarely important anyway, has the possibility of being wrong (at least that's my reading of the API), and can be computed (more accurately) if required.
Sounds good to me. It makes the API so much simpler to use.
I just thought that since it's similar to read() it could behave like one.
I find it strange that you need the pool to allocate the unknown len, but you don't need one to allocate a certain amount of bytes. To make the API consistent I'd suggest it to be:
my $data = $bb->flatten($p, [$len]);
i.e. always pass $p, and use apr_pcalloc to allocate $len bytes if that optional argument is passed.
Now that you mention that, we could really have one interface instead of 2. If you pass the optional read length value it'll use flatten if you don't it'll use pflatten. make it use the pool object in both but ignore in flatten. So you get a 1:1 mapping to perl's read (we may even support the offset argument later on) ;)
Hell, why not write PerlIO::BB ;)
I'm already working on APR::TieBrigade, which lets you manipulate a brigade like a perl $fh :)
Cool. Though this is probably something that is not quite needed at the moment.
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
