|
APR::Brigade - Perl API for manipulating APR Bucket Brigades |
cleanupconcatdestroyis_emptyfirstflatteninsert_headinsert_taillastlengthnewnextpoolprevsplit
APR::Brigade - Perl API for manipulating APR Bucket Brigades
use APR::Brigade ();
$bb = APR::Brigade->new($r->pool, $c->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();
APR::Brigade allows you to create, manipulate and delete APR bucket
brigades.
APR::Brigade provides the following functions and/or methods:
cleanupEmpty out an entire bucket brigade:
$bb->cleanup;
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )This method destroys all of the buckets within the bucket brigade's
bucket list. This is similar to destroy()|/C_destroy_, except
that it does not deregister the brigade's pool()|/C_pool_
cleanup function.
Generally, you should use destroy()|/C_destroy_. 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.
concatConcatenate brigade $bb2 onto the end of brigade $bb1, leaving
brigade $bb2 empty:
$bb1->concat($bb2);
$bb1
( APR::Brigade object|docs::2.0::api::APR::Brigade )$bb2
( APR::Brigade object|docs::2.0::api::APR::Brigade )
destroydestroy an entire bucket brigade, includes all of the buckets within the bucket brigade's bucket list.
$bb->destroy();
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )APR::Error|docs::2.0::api::APR::Error
is_emptyTest whether the bucket brigade is empty
$ret = $bb->is_empty();
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$ret ( boolean )
firstReturn the first bucket in a brigade
$b_first = $bb->first;
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b_first
( APR::Bucket object|docs::2.0::api::APR::Bucket )$bb.
undef is returned if there are no buckets in $bb.
flattenGet the data from buckets in the bucket brigade as one string
$len = $bb->flatten($buffer); $len = $bb->flatten($buffer, $wanted);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$buffer ( SCALAR )$wanted ( number )$wanted
is specified -- that number or less bytes will be returned.
$len ( number )$buffer gets populated with the string that is read. It will
contain an empty string if there was nothing to read.
APR::Error|docs::2.0::api::APR::Error
insert_headInsert a list of buckets at the front of a brigade
$bb->insert_head($b);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b
( APR::Bucket object|docs::2.0::api::APR::Bucket )
insert_tailInsert a list of buckets at the end of a brigade
$bb->insert_tail($b);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b
( APR::Bucket object|docs::2.0::api::APR::Bucket )
lastReturn the last bucket in the brigade
$b_last = $bb->last;
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b_last
( APR::Bucket object|docs::2.0::api::APR::Bucket )$bb.
undef is returned if there are no buckets in $bb.
lengthReturn the total length of the data in the brigade (not the number of buckets)
$len = $bb->length;
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$len ( number )
newmy $nbb = APR::Brigade->new($p, $bucket_alloc); my $nbb = $bb->new($p, $bucket_alloc);
$bb
( APR::Brigade object or class|docs::2.0::api::APR::Brigade )$p
( APR::Pool object|docs::2.0::api::APR::Pool )$bucket_alloc
( APR::BucketAlloc object|docs::2.0::api::APR::BucketAlloc )$nbb
( APR::Brigade object|docs::2.0::api::APR::Brigade )Example:
Create a new bucket brigade, using the request object's pool:
use Apache::Connection (); use Apache::RequestRec (); use APR::Brigade (); my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc);
nextReturn the next bucket in a brigade
$b_next = $bb->next($b);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b
( APR::Bucket object|docs::2.0::api::APR::Bucket )$b_next is located
$b_next
( APR::Bucket object|docs::2.0::api::APR::Bucket )$b.
undef is returned if there is no next bucket (i.e. $b is the
last bucket).
poolThe pool the brigade is associated with.
$pool = $bb->pool;
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$pool
( APR::Pool object|docs::2.0::api::APR::Pool )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.
prevReturn the previous bucket in the brigade
$b_prev = $bb->prev($b);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b
( APR::Bucket object|docs::2.0::api::APR::Bucket )$b_prev
$b_prev
( APR::Bucket object|docs::2.0::api::APR::Bucket )$b.
undef is returned if there is no previous bucket (i.e. $b is the
first bucket).
splitSplit a bucket brigade into two, such that the given bucket is the first in the new bucket brigade.
$bb2 = $bb->split($b);
$bb
( APR::Brigade object|docs::2.0::api::APR::Brigade )$b
( APR::Bucket object|docs::2.0::api::APR::Bucket )$bb2
( APR::Brigade object|docs::2.0::api::APR::Brigade )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);
$bb1->insert_tail(APR::Bucket->new("1"));
$bb1->insert_tail(APR::Bucket->new("2"));
$bb1->insert_tail(APR::Bucket->new("3"));
$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 $bb1 contains bucket ``1''. $bb2 contains buckets: ``2'', ``3''
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
The mod_perl development team and numerous contributors.
|
APR::Brigade - Perl API for manipulating APR Bucket Brigades |