=head1 NAME APR::Brigade - Perl API for manipulating APR Bucket Brigades =head1 Synopsis use APR::Brigade (); $bb = APR::Brigade->new($r->pool, $c->bucket_alloc); $ba = $bb->bucket_alloc(); $pool = $bb->pool; $bb->insert_head($b); $bb->insert_tail($b); $b_first = $bb->first; $b_last = $bb->last; $b_prev = $bb->prev($b_last); $b_next = $bb->next($b); $bb2 = APR::Brigade->new($r->pool, $c->bucket_alloc); $bb1->concat($bb2); $len = $bb->flatten($data); $len = $bb2->flatten($data, $wanted); $len = $bb->length; $bb3 = $bb->split($b_last); last if $bb->is_empty(); $bb->cleanup(); $bb->destroy(); =head1 Description C allows you to create, manipulate and delete APR bucket brigades. =head1 API C provides the following functions and/or methods: =head2 C Empty out an entire bucket brigade: $bb->cleanup; =over 4 =item obj: C<$bb> ( C> ) The brigade to cleanup =item ret: no return value =item since: 2.0.00 =back This method destroys all of the buckets within the bucket brigade's bucket list. This is similar to C>, except that it does not deregister the brigade's C> cleanup function. Generally, you should use C>. This function can be useful in situations where you have a single brigade that you wish to reuse many times by destroying all of the buckets in the brigade and putting new buckets into it later. =head2 C Concatenate brigade C<$bb2> onto the end of brigade C<$bb1>, leaving brigade C<$bb2> empty: $bb1->concat($bb2); =over 4 =item obj: C<$bb1> ( C> ) The brigade to concatenate to. =item arg1: C<$bb2> ( C> ) The brigade to concatenate and empty afterwards. =item ret: no return value =item since: 2.0.00 =back =head2 C destroy an entire bucket brigade, includes all of the buckets within the bucket brigade's bucket list. $bb->destroy(); =over 4 =item obj: C<$bb> ( C> ) The bucket brigade to destroy. =item ret: no return value =item excpt: C> =item since: 2.0.00 =back =head2 C Test whether the bucket brigade is empty $ret = $bb->is_empty(); =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$ret> ( boolean ) =item since: 2.0.00 =back =head2 C Return the first bucket in a brigade $b_first = $bb->first; =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$b_first> ( C> ) The first bucket in the bucket brigade C<$bb>. C is returned if there are no buckets in C<$bb>. =item since: 2.0.00 =back =head2 C Get the data from buckets in the bucket brigade as one string $len = $bb->flatten($buffer); $len = $bb->flatten($buffer, $wanted); =over 4 =item obj: C<$bb> ( C> ) =item arg1: C<$buffer> ( SCALAR ) The buffer to fill. All previous data will be lost. =item opt arg2: C<$wanted> ( number ) If no argument is passed then all data will be returned. If C<$wanted> is specified -- that number or less bytes will be returned. =item ret: C<$len> ( number ) How many bytes were actually read. C<$buffer> gets populated with the string that is read. It will contain an empty string if there was nothing to read. =item since: 2.0.00 =item excpt: C> =back =head2 C Insert a list of buckets at the front of a brigade $bb->insert_head($b); =over 4 =item obj: C<$bb> ( C> ) Brigade to insert into =item arg1: C<$b> ( C> ) the bucket to insert. More buckets could be attached to that bucket. =item ret: no return value =item since: 2.0.00 =back =head2 C Insert a list of buckets at the end of a brigade $bb->insert_tail($b); =over 4 =item obj: C<$bb> ( C> ) Brigade to insert into =item arg1: C<$b> ( C> ) the bucket to insert. More buckets could be attached to that bucket. =item ret: no return value =item since: 2.0.00 =back =head2 C Return the last bucket in the brigade $b_last = $bb->last; =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$b_last> ( C> ) The last bucket in the bucket brigade C<$bb>. C is returned if there are no buckets in C<$bb>. =item since: 2.0.00 =back =head2 C Return the total length of the data in the brigade (not the number of buckets) $len = $bb->length; =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$len> ( number ) =item since: 2.0.00 =back =head2 C my $nbb = APR::Brigade->new($p, $bucket_alloc); my $nbb = $bb->new($p, $bucket_alloc); =over 4 =item obj: C<$bb> ( C> ) =item arg1: C<$p> ( C> ) =item arg2: C<$bucket_alloc> ( C> ) =item ret: C<$nbb> ( C> ) a newly created bucket brigade object =item since: 2.0.00 =back Example: Create a new bucket brigade, using the request object's pool: use Apache2::Connection (); use Apache2::RequestRec (); use APR::Brigade (); my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc); =head2 C Get the bucket allocator associated with this brigade. my $ba = $bb->bucket_alloc(); =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$ba> ( C> ) =item since: 2.0.00 =back =head2 C Return the next bucket in a brigade $b_next = $bb->next($b); =over 4 =item obj: C<$bb> ( C> ) =item arg1: C<$b> ( C> ) The bucket after which the next bucket C<$b_next> is located =item ret: C<$b_next> ( C> ) The next bucket after bucket C<$b>. C is returned if there is no next bucket (i.e. C<$b> is the last bucket). =item since: 2.0.00 =back =head2 C The pool the brigade is associated with. $pool = $bb->pool; =over 4 =item obj: C<$bb> ( C> ) =item ret: C<$pool> ( C> ) =item since: 2.0.00 =back The data is not allocated out of the pool, but a cleanup is registered with this pool. If the brigade is destroyed by some mechanism other than pool destruction, the destroying function is responsible for killing the registered cleanup. =head2 C Return the previous bucket in the brigade $b_prev = $bb->prev($b); =over 4 =item obj: C<$bb> ( C> ) =item arg1: C<$b> ( C> ) The bucket located after bucket C<$b_prev> =item ret: C<$b_prev> ( C> ) The bucket located before bucket C<$b>. C is returned if there is no previous bucket (i.e. C<$b> is the first bucket). =item since: 2.0.00 =back =head2 C Split a bucket brigade into two, such that the given bucket is the first in the new bucket brigade. $bb2 = $bb->split($b); =over 4 =item obj: C<$bb> ( C> ) The brigade to split =item arg1: C<$b> ( C> ) The first bucket of the new brigade =item ret: C<$bb2> ( C> ) The new brigade. =item since: 2.0.00 =back This function is useful when a filter wants to pass only the initial part of a brigade to the next filter. Example: Create a bucket brigade with three buckets, and split it into two brigade such that the second brigade will have the last two buckets. my $bb1 = APR::Brigade->new($r->pool, $c->bucket_alloc); my $ba = $c->bucket_alloc(); $bb1->insert_tail(APR::Bucket->new($ba, "1")); $bb1->insert_tail(APR::Bucket->new($ba, "2")); $bb1->insert_tail(APR::Bucket->new($ba, "3")); C<$bb1> now contains buckets "1", "2", "3". Now do the split at the second bucket: my $b = $bb1->first; # 1 $b = $bb1->next($b); # 2 my $bb2 = $bb1->split($b); Now C<$bb1> contains bucket "1". C<$bb2> contains buckets: "2", "3" =head1 See Also L. =head1 Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. =head1 Authors L. =cut