home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Bucket.pm < prev    next >
Encoding:
Perl POD Document  |  2004-09-23  |  13.2 KB  |  697 lines

  1. # /*
  2. #  * *********** WARNING **************
  3. #  * This file generated by ModPerl::WrapXS/0.01
  4. #  * Any changes made here will be lost
  5. #  * ***********************************
  6. #  * 01: lib/ModPerl/Code.pm:701
  7. #  * 02: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:584
  8. #  * 03: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:1100
  9. #  * 04: Makefile.PL:335
  10. #  * 05: Makefile.PL:283
  11. #  * 06: Makefile.PL:51
  12. #  */
  13.  
  14.  
  15. package APR::Bucket;
  16.  
  17. use strict;
  18. use warnings FATAL => 'all';
  19.  
  20.  
  21. use APR ();
  22. use APR::XSLoader ();
  23. our $VERSION = '0.01';
  24. APR::XSLoader::load __PACKAGE__;
  25.  
  26.  
  27.  
  28. 1;
  29. __END__
  30.  
  31. =head1 NAME
  32.  
  33. APR::Bucket - Perl API for manipulating APR Buckets
  34.  
  35.  
  36.  
  37.  
  38. =head1 Synopsis
  39.  
  40.   use APR::Bucket ();
  41.   my $ba = $c->bucket_alloc;
  42.   
  43.   $b1 = APR::Bucket->new("aaa");
  44.   $b2 = APR::Bucket::eos_create($ba);
  45.   $b3 = APR::Bucket::flush_create($ba);
  46.   
  47.   $b2->is_eos;
  48.   $b3->is_flush;
  49.   
  50.   $len = $b1->length;
  51.   $len = $b1->read($data);
  52.   $type = $b1->type;
  53.   
  54.   $b1->insert_after($b2);
  55.   $b1->insert_before($b3);
  56.   $b1->remove;
  57.   $b1->destroy;
  58.   
  59.   $b2->delete; # remove+destroy
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. =head1 Description
  68.  
  69. C<APR::Bucket> allows you to create, manipulate and delete APR
  70. buckets.
  71.  
  72. You will probably find the various insert methods confusing, the tip
  73. is to read the function right to left. The following code sample helps
  74. to visualize the operations:
  75.  
  76.   my $bb = APR::Brigade->new($r->pool, $ba);
  77.   my $d1 = APR::Bucket->new("d1");
  78.   my $d2 = APR::Bucket->new("d2");
  79.   my $f1 = APR::Bucket::flush_create($ba);
  80.   my $f2 = APR::Bucket::flush_create($ba);
  81.   my $e1 = APR::Bucket::eos_create($ba);
  82.                            # head->tail
  83.   $bb->insert_head(  $d1); # head->d1->tail
  84.   $d1->insert_after( $d2); # head->d1->d2->tail
  85.   $d2->insert_before($f1); # head->d1->f1->d2->tail
  86.   $d2->insert_after( $f2); # head->d1->f1->d2->f2->tail
  87.   $bb->insert_tail(  $e1); # head->d1->f1->d2->f2->e1->tail
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. =head1 API
  97.  
  98. C<APR::Bucket> provides the following functions and/or methods:
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. =head2 C<delete>
  106.  
  107. Tell the bucket to remove itself from the bucket brigade it belongs
  108. to, and destroy itself.
  109.  
  110.   $bucket->delete();
  111.  
  112. =over 4
  113.  
  114. =item obj: C<$bucket>
  115. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  116.  
  117. =item ret: no return value
  118.  
  119. =item since: 1.99_16
  120.  
  121. =back
  122.  
  123. If the bucket is not attached to any bucket brigade then this
  124. operation just destroys the bucket.
  125.  
  126. C<delete> is a convenience wrapper, internally doing:
  127.  
  128.   $b->remove;
  129.   $b->destroy;
  130.  
  131. Examples:
  132.  
  133. Assuming that C<$bb> already exists and filled with buckets, replace
  134. the existing data buckets with new buckets with upcased data;
  135.  
  136.   for (my $b = $bb->first; $b; $b = $bb->next($b)) {
  137.      if ($b->read(my $data)) {
  138.           my $nb = APR::Bucket->new(uc $data);
  139.           $b->insert_before($nb);
  140.           $b->delete;
  141.           $b = $nb;
  142.       }
  143.   }
  144.  
  145.  
  146.  
  147.  
  148.  
  149. =head2 C<destroy>
  150.  
  151. Free the resources used by a bucket. If multiple buckets refer to the
  152. same resource it is freed when the last one goes away.
  153.  
  154.   $bucket->destroy();
  155.  
  156. =over 4
  157.  
  158. =item obj: C<$bucket>
  159. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  160.  
  161. =item ret: no return value
  162.  
  163. =item since: 1.99_16
  164.  
  165. =back
  166.  
  167. A bucket needs to be destroyed if it was L<removed|/C_remove_> from a
  168. bucket brigade, to avoid memory leak.
  169.  
  170. If a bucket is linked to a bucket brigade, it needs to be
  171. L<removed|/C_remove_> from it, before it can be destroyed.
  172.  
  173. Usually instead of calling:
  174.  
  175.   $b->remove;
  176.   $b->destroy;
  177.  
  178. it's better to call C<L<delete|/C_delete_>> which does exactly that.
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. =head2 C<eos_create>
  186.  
  187. Create an I<EndOfStream> bucket.
  188.  
  189.   $b = APR::Bucket::eos_create($ba);
  190.  
  191. =over 4
  192.  
  193. =item arg1: C<$ba>
  194. ( C<L<APR::BucketAlloc object|docs::2.0::api::APR::BucketAlloc>> )
  195.  
  196. The freelist from which this bucket should be allocated
  197.  
  198. =item ret: C<$b>
  199. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  200.  
  201. The new bucket
  202.  
  203. =item since: 1.99_10
  204.  
  205. =back
  206.  
  207. This bucket type indicates that there is no more data coming from down
  208. the filter stack.  All filters should flush any buffered data at this
  209. point.
  210.  
  211. Example:
  212.  
  213.   use APR::Bucket ();
  214.   use Apache::Connection ();
  215.   my $ba = $c->bucket_alloc;
  216.   my $eos_b = APR::Bucket::eos_create($ba);
  217.  
  218.  
  219.  
  220.  
  221.  
  222. =head2 C<flush_create>
  223.  
  224. Create a flush bucket.
  225.  
  226.   $b = APR::Bucket::flush_create($ba);
  227.  
  228. =over 4
  229.  
  230. =item arg1: C<$ba>
  231. ( C<L<APR::BucketAlloc object|docs::2.0::api::APR::BucketAlloc>> )
  232.  
  233. The freelist from which this bucket should be allocated
  234.  
  235. =item ret: C<$b>
  236. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  237.  
  238. The new bucket
  239.  
  240. =item since: 1.99_10
  241.  
  242. =back
  243.  
  244. This bucket type indicates that filters should flush their data.
  245. There is no guarantee that they will flush it, but this is the best we
  246. can do.
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253. =head2 C<insert_after>
  254.  
  255. Insert a list of buckets after a specified bucket
  256.  
  257.   $after_bucket->insert_after($add_bucket);
  258.  
  259. =over 4
  260.  
  261. =item obj: C<$after_bucket>
  262. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  263.  
  264. The bucket to insert after
  265.  
  266. =item arg1: C<$add_bucket>
  267. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  268.  
  269. The buckets to insert. It says buckets, since C<$add_bucket> may have
  270. more buckets attached after itself.
  271.  
  272. =item ret: no return value
  273.  
  274. =item since: 1.99_10
  275.  
  276. =back
  277.  
  278.  
  279.  
  280.  
  281.  
  282. =head2 C<insert_before>
  283.  
  284. Insert a list of buckets before a specified bucket
  285.  
  286.   $before_bucket->insert_before($add_bucket);
  287.  
  288. =over 4
  289.  
  290. =item obj: C<$before_bucket>
  291. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  292.  
  293. The bucket to insert before
  294.  
  295. =item arg1: C<$add_bucket>
  296. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  297.  
  298. The buckets to insert. It says buckets, since C<$add_bucket> may have
  299. more buckets attached after itself.
  300.  
  301. =item ret: no return value
  302.  
  303. =item since: 1.99_10
  304.  
  305. =back
  306.  
  307.  
  308.  
  309.  
  310.  
  311. =head2 C<is_eos>
  312.  
  313. Determine if a bucket is an EOS bucket
  314.  
  315.   $ret = $bucket->is_eos();
  316.  
  317. =over 4
  318.  
  319. =item obj: C<$bucket>
  320. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  321.  
  322. =item ret: C<$ret> ( boolean )
  323.  
  324. =item since: 1.99_10
  325.  
  326. =back
  327.  
  328.  
  329.  
  330.  
  331.  
  332. =head2 C<is_flush>
  333.  
  334. Determine if a bucket is a FLUSH bucket
  335.  
  336.   $ret = $bucket->is_flush();
  337.  
  338. =over 4
  339.  
  340. =item obj: C<$bucket>
  341. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  342.  
  343. =item ret: C<$ret> ( boolean )
  344.  
  345. =item since: 1.99_10
  346.  
  347. =back
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356. =head2 C<length>
  357.  
  358. Get the length of the data in the bucket.
  359.  
  360.   $len = $b->length;
  361.  
  362. =over 4
  363.  
  364. =item obj: C<$b>
  365. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  366.  
  367. =item ret: C<$len> ( integer )
  368.  
  369. If the length is unknown, C<$len> value will be -1.
  370.  
  371. =item since: 1.99_10
  372.  
  373. =back
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380. =head2 C<new>
  381.  
  382. Create a new bucket and initialize it with data:
  383.  
  384.   $nb = APR::Bucket->new($data);
  385.   $nb =          $b->new($data);
  386.   $nb = APR::Bucket->new($data, $offset);
  387.   $nb = APR::Bucket->new($data, $offset, $len);
  388.  
  389. =over 4
  390.  
  391. =item obj: C<$b>
  392. ( C<L<APR::Bucket object or class|docs::2.0::api::APR::Bucket>> )
  393.  
  394. =item arg1: C<$data> ( string )
  395.  
  396. The data to initialize with.
  397.  
  398. B<Important:> in order to avoid unnecessary data copying the variable
  399. is stored in the bucket object. That means that if you modify C<$data>
  400. after passing it to C<new()> you will modify the data in the bucket as
  401. well. To avoid that pass to C<new()> a copy which you won't modify.
  402.  
  403. =item opt arg2: C<$offset> ( number )
  404.  
  405. Optional offset inside C<$data>. Default: 0.
  406.  
  407. =item opt arg3: C<$len> ( number )
  408.  
  409. Optional partial length to read.
  410.  
  411. If C<$offset> is specified, then:
  412.  
  413.   length $buffer - $offset;
  414.  
  415. will be used. Otherwise the default is to use:
  416.  
  417.   length $buffer;
  418.  
  419. =item ret: C<$nb>
  420. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  421.  
  422. a newly created bucket object
  423.  
  424. =item since: 1.99_10
  425.  
  426. =back
  427.  
  428. Examples:
  429.  
  430. =over
  431.  
  432. =item *
  433.  
  434. Create a new bucket using a whole string:
  435.  
  436.   use APR::Bucket ();
  437.   my $data = "my data";
  438.   my $b = APR::Bucket->new($data);
  439.  
  440. now the bucket contains the string I<'my data'>.
  441.  
  442. =item *
  443.  
  444. Create a new bucket using a sub-string:
  445.  
  446.   use APR::Bucket ();
  447.   my $data   = "my data";
  448.   my $offset = 3;
  449.   my $b = APR::Bucket->new($data, $offset);
  450.  
  451. now the bucket contains the string I<'data'>.
  452.  
  453. =item *
  454.  
  455. Create a new bucket not using the whole length and starting from an
  456. offset:
  457.  
  458.   use APR::Bucket ();
  459.   my $data   = "my data";
  460.   my $offset = 3;
  461.   my $len    = 3;
  462.   my $b = APR::Bucket->new($data, $offset, $len);
  463.  
  464. now the bucket contains the string I<'dat'>.
  465.  
  466. =back
  467.  
  468.  
  469.  
  470.  
  471.  
  472. =head2 C<read>
  473.  
  474. Read the data from the bucket.
  475.  
  476.   $len = $b->read($buffer,);
  477.   $len = $b->read($buffer, $block);
  478.  
  479. =over 4
  480.  
  481. =item obj: C<$b>
  482. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  483.  
  484. The bucket to read from
  485.  
  486. =item arg1: C<$buffer> ( SCALAR )
  487.  
  488. The buffer to fill. All previous data will be lost.
  489.  
  490. =item opt arg2: C<$block> ( C<L<APR::Const :read_type
  491. constant|docs::2.0::api::APR::Const/C__read_type_>> )
  492.  
  493. optional reading mode constant.
  494.  
  495. By default the read is blocking, via C<L<APR::BLOCK_READ
  496. constant|docs::2.0::api::APR::Const/C_APR__BLOCK_READ_>>.
  497.  
  498. =item ret: C<$len> ( number )
  499.  
  500. How many bytes were actually read
  501.  
  502. C<$buffer> gets populated with the string that is read. It will
  503. contain an empty string if there was nothing to read.
  504.  
  505. =item since: 1.99_15
  506.  
  507. =item excpt: C<L<APR::Error|docs::2.0::api::APR::Error>>
  508.  
  509. =back
  510.  
  511. It's important to know that certain bucket types (e.g. file bucket),
  512. may perform a split and insert extra buckets following the current
  513. one. Therefore never call C<L<$b-E<gt>remove|/C_remove_>>, before
  514. calling C<$b-E<gt>read>, or you may lose data.
  515.  
  516. Examples:
  517.  
  518. Blocking read:
  519.  
  520.   my $len = $b->read(my $buffer);
  521.  
  522. Non-blocking read:
  523.  
  524.   use APR::Const -compile 'NONBLOCK_READ';
  525.   my $len = $b->read(my $buffer, APR::NONBLOCK_READ);
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. =head2 C<remove>
  533.  
  534. Tell the bucket to remove itself from the bucket brigade it belongs
  535. to.
  536.  
  537.   $bucket->remove();
  538.  
  539. =over 4
  540.  
  541. =item obj: C<$bucket>
  542. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  543.  
  544. =item ret: no return value
  545.  
  546. =item since: 1.99_10
  547.  
  548. =back
  549.  
  550. If the bucket is not attached to any bucket brigade then this
  551. operation doesn't do anything.
  552.  
  553. When the bucket is removed, it's not not destroyed. Usually this is
  554. done in order to move the bucket to another bucket brigade. Or to copy
  555. the data way before destroying the bucket.  If the bucket wasn't moved
  556. to another bucket brigade it must be L<destroyed|/C_destroy_>.
  557.  
  558. Examples:
  559.  
  560. Assuming that C<$bb1> already exists and filled with buckets, move
  561. every odd bucket number to C<$bb2> and every even to C<$bb3>:
  562.  
  563.   my $bb2 = APR::Brigade->new($c->pool, $c->bucket_alloc);
  564.   my $bb3 = APR::Brigade->new($c->pool, $c->bucket_alloc);
  565.   my $count = 0;
  566.   while (my $bucket = $bb->first) {
  567.       $count++;
  568.       $bucket->remove;
  569.       $count % 2
  570.           ? $bb2->insert_tail($bucket)
  571.           : $bb3->insert_tail($bucket);
  572.   }
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579. =head2 C<type>
  580.  
  581. Get the type of the data in the bucket.
  582.  
  583.   $type = $b->type;
  584.  
  585. =over 4
  586.  
  587. =item obj: C<$b>
  588. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  589.  
  590. =item ret: C<$type>
  591. ( C<L<APR::BucketType object|docs::2.0::api::APR::BucketType>> )
  592.  
  593. =item since: 1.99_10
  594.  
  595. =back
  596.  
  597. You need to invoke
  598. C<L<APR::BucketType|docs::2.0::api::APR::BucketType>> methods to
  599. access the data.
  600.  
  601. Example:
  602.  
  603. Create a flush bucket and read its type's name:
  604.  
  605.   use APR::Bucket ();
  606.   use APR::BucketType ();
  607.   my $b = APR::Bucket::flush_create($ba);
  608.   my $type = $b->type;
  609.   my $type_name =  $type->name; # FLUSH
  610.  
  611. The type name will be I<'FLUSH'> in this example.
  612.  
  613.  
  614. =head1 Unsupported API
  615.  
  616. C<APR::Socket> also provides auto-generated Perl interface for a few
  617. other methods which aren't tested at the moment and therefore their
  618. API is a subject to change. These methods will be finalized later as a
  619. need arises. If you want to rely on any of the following methods
  620. please contact the L<the mod_perl development mailing
  621. list|maillist::dev> so we can help each other take the steps necessary
  622. to shift the method to an officially supported API.
  623.  
  624.  
  625.  
  626.  
  627.  
  628. =head2 C<data>
  629.  
  630.   $data = $b->data;
  631.  
  632. Gives a C pointer to the address of the data in the bucket. I can't
  633. see what use can be done of it in Perl.
  634.  
  635. =over 4
  636.  
  637. =item obj: C<$b>
  638. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  639.  
  640. =item ret: C<$data> ( C pointer )
  641.  
  642. =item since: subject to change
  643.  
  644. =back
  645.  
  646.  
  647. =head2 C<start>
  648.  
  649.   $start = $b->start;
  650.  
  651. It gives the offset to when a new bucket is created with a non-zero
  652. offset value:
  653.  
  654.   my $b = APR::Bucket->new($data, $offset, $len);
  655.  
  656. So if the offset was 3. C<$start> will be 3 too.
  657.  
  658. I fail to see what it can be useful for to the end user (it's mainly
  659. used internally).
  660.  
  661. =over 4
  662.  
  663. =item obj: C<$b>
  664. ( C<L<APR::Bucket object|docs::2.0::api::APR::Bucket>> )
  665.  
  666. =item ret: C<$start> ( offset number )
  667.  
  668. =item since: subject to change
  669.  
  670. =back
  671.  
  672.  
  673. =head1 See Also
  674.  
  675. L<mod_perl 2.0 documentation|docs::2.0::index>.
  676.  
  677.  
  678.  
  679.  
  680. =head1 Copyright
  681.  
  682. mod_perl 2.0 and its core modules are copyrighted under
  683. The Apache Software License, Version 2.0.
  684.  
  685.  
  686.  
  687.  
  688. =head1 Authors
  689.  
  690. L<The mod_perl development team and numerous
  691. contributors|about::contributors::people>.
  692.  
  693. =cut
  694.  
  695.