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 / Pool.pm < prev    next >
Encoding:
Perl POD Document  |  2004-09-23  |  9.7 KB  |  482 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::Pool;
  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::Pool - Perl API for APR pools
  34.  
  35.  
  36.  
  37.  
  38. =head1 Synopsis
  39.  
  40.   use APR::Pool ();
  41.   
  42.   my $sp = $r->pool->new;
  43.   my $sp2 = APR::Pool->new;
  44.   
  45.   # $sp3 is a subpool of $sp,
  46.   # which in turn is a subpool of $r->pool
  47.   $sp3 = $sp->new;
  48.   print '$r->pool is an ancestor of $sp3'
  49.       if $r->pool->is_ancestor($sp3);
  50.   # but sp2 is not a sub-pool of $r->pool
  51.   print '$r->pool is not an ancestor of $sp2'
  52.       unless $r->pool->is_ancestor($sp2);
  53.   
  54.   # $sp4 and $sp are the same pool (though you can't
  55.   # compare the handle as variables)
  56.   my $sp4 = $sp3->parent_get;
  57.   
  58.  
  59.   # register a dummy cleanup function
  60.   # that just prints the passed args
  61.   $sp->cleanup_register(sub { print @{ $_[0] || [] } }, [1..3]);
  62.   
  63.   # tag the pool
  64.   $sp->tag("My very best pool");
  65.   
  66.   # clear the pool
  67.   $sp->clear();
  68.   
  69.   # destroy sub pool
  70.   $sp2->destroy;
  71.  
  72.  
  73. =head1 Description
  74.  
  75. C<APR::Pool> provides an access to APR pools, which are used for an
  76. easy memory management.
  77.  
  78. Different pools have different life scopes and therefore one doesn't
  79. need to free allocated memory explicitly, but instead it's done when
  80. the pool's life is getting to an end. For example a request pool is
  81. created at the beginning of a request and destroyed at the end of it,
  82. and all the memory allocated during the request processing using the
  83. request pool is freed at once at the end of the request.
  84.  
  85. Most of the time you will just pass various pool objects to the
  86. methods that require them. And you must understand the scoping of the
  87. pools, since if you pass a long lived server pool to a method that
  88. needs the memory only for a short scoped request, you are going to
  89. leak memory. A request pool should be used in such a case. And vice
  90. versa, if you need to allocate some memory for a scope longer than a
  91. single request, then a request pool is inappropriate, since when the
  92. request will be over, the memory will be freed and bad things may
  93. happen.
  94.  
  95. If you need to create a new pool, you can always do that via the
  96. C<L<new()|/C_new_>> method.
  97.  
  98.  
  99. =head1 API
  100.  
  101. C<APR::Pool> provides the following functions and/or methods:
  102.  
  103.  
  104.  
  105.  
  106.  
  107. =head2 C<cleanup_register>
  108.  
  109. Register cleanup callback to run
  110.  
  111.   $pool->cleanup_register($callback);
  112.   $pool->cleanup_register($callback, $arg);
  113.  
  114. =over 4
  115.  
  116. =item obj: C<$pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  117.  
  118. The pool object to register the cleanup callback for
  119.  
  120. =item arg1: C<$callback> ( CODE ref or sub name )
  121.  
  122. a cleanup callback CODE reference or just a name of the subroutine
  123. (fully qualified unless defined in the current package).
  124.  
  125. =item opt arg2: C<$arg> ( SCALAR )
  126.  
  127. If this optional argument is passed, the C<$callback> function will
  128. receive it as the first and only argument when executed.
  129.  
  130. To pass more than one argument, use an ARRAY or a HASH reference
  131.  
  132. =item ret: no return value
  133.  
  134. =item excpt:
  135.  
  136. if the registered callback fails, it happens when the pool is
  137. destroyed. The destruction is performed by Apache and it ignores any
  138. failures. Even if it didn't ignore the failures, most of the time the
  139. pool is destroyed when a request or connection handlers are long gone.
  140. However the error B<is> logged to F<error_log>, so if you monitor that
  141. file you will spot if there are any problems with it.
  142.  
  143. =item since: 1.99_14
  144.  
  145. =back
  146.  
  147. If there is more than one callback registered (when
  148. C<cleanup_register> is called more than once on the same pool object),
  149. the last registered callback will be executed first (LIFO).
  150.  
  151. Examples:
  152.  
  153. No arguments, using anon sub as a cleanup callback:
  154.  
  155.   $r->pool->cleanup_register(sub { warn "running cleanup" });
  156.  
  157. One or more arguments using a cleanup code reference:
  158.  
  159.   $r->pool->cleanup_register(\&cleanup, $r);
  160.   $r->pool->cleanup_register(\&cleanup, [$r, $foo]);
  161.   sub cleanup {
  162.       my @args = (@_ && ref $_[0] eq ARRAY) ? @{ +shift } : shift;
  163.       my $r = shift @args;
  164.       warn "cleaning up";
  165.   }
  166.  
  167. No arguments, using a function name as a cleanup callback:
  168.  
  169.   $r->pool->cleanup_register('foo');
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. =head2 C<clear>
  183.  
  184. Clear all memory in the pool and run all the registered cleanups. This
  185. also destroys all sub-pools.
  186.  
  187.   $pool->clear();
  188.  
  189. =over 4
  190.  
  191. =item obj: C<$pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  192.  
  193. The pool to clear
  194.  
  195. =item ret: no return value
  196.  
  197. =item since: 1.99_14
  198.  
  199. =back
  200.  
  201. This method differs from C<L<destroy()|/C_destroy_>> in that it is not
  202. freeing the previously allocated, but allows the pool to re-use it for
  203. the future memory allocations.
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215. =head2 C<DESTROY>
  216.  
  217. C<DESTROY> is an alias to C<L<destroy|/C_destroy_>>. It's there so
  218. that custom C<APR::Pool> objects will get properly cleaned up, when
  219. the pool object goes out of scope. If you ever want to destroy an
  220. C<APR::Pool> object before it goes out of scope, use
  221. C<L<destroy|/C_destroy_>>.
  222.  
  223.  
  224. =over 4
  225.  
  226. =item since: 1.99_14
  227.  
  228. =back
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. =head2 C<destroy>
  243.  
  244. Destroy the pool.
  245.  
  246.   $pool->destroy();
  247.  
  248. =over 4
  249.  
  250. =item obj: C<$pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  251.  
  252. The pool to destroy
  253.  
  254. =item ret: no return value
  255.  
  256. =item since: 1.99_14
  257.  
  258. =back
  259.  
  260. This method takes a similar action to C<L<clear()|/C_clear_>> and then
  261. frees all the memory.
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. =head2 C<is_ancestor>
  274.  
  275. Determine if pool a is an ancestor of pool b
  276.  
  277.   $ret = $pool_a->is_ancestor($pool_b);
  278.  
  279. =over 4
  280.  
  281. =item obj: C<$pool_a> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  282.  
  283. The pool to search
  284.  
  285. =item arg1: C<$pool_b> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  286.  
  287. The pool to search for
  288.  
  289. =item ret: C<$ret> ( integer )
  290.  
  291. True if C<$pool_a> is an ancestor of C<$pool_b>.
  292.  
  293. =item since: 1.99_14
  294.  
  295. =back
  296.  
  297. For example create a sub-pool of a given pool and check that the pool
  298. is an ancestor of that sub-pool:
  299.  
  300.   use APR::Pool ();
  301.   my $pp = $r->pool;
  302.   my $sp = $pp->new();
  303.   $pp->is_ancestor($sp) or die "Don't mess with genes!";
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313. =head2 C<new>
  314.  
  315. Create a new sub-pool
  316.  
  317.   my $pool_child = $pool_parent->new;
  318.   my $pool_child = APR::Pool->new;
  319.  
  320. =over 4
  321.  
  322. =item obj: C<$pool_parent> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  323.  
  324. The parent pool.
  325.  
  326. If you don't have a parent pool to create the sub-pool from, you can
  327. use this object method as a class method, in which case the sub-pool
  328. will be created from the global pool:
  329.  
  330.   my $pool_child = APR::Pool->new;
  331.  
  332. =item ret: C<$pool_child> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  333.  
  334. The child sub-pool
  335.  
  336. =item since: 1.99_14
  337.  
  338. =back
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348. =head2 C<parent_get>
  349.  
  350. Get the parent pool
  351.  
  352.   $parent_pool = $child_pool->parent_get();
  353.  
  354. =over 4
  355.  
  356. =item obj: C<$child_pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  357.  
  358. the child pool
  359.  
  360. =item ret: C<$parent_pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  361.  
  362. the parent pool. C<undef> if there is no parent pool (which is the
  363. case for the top-most global pool).
  364.  
  365. =item since: 1.99_14
  366.  
  367. =back
  368.  
  369. Example: Calculate how big is the pool's ancestry:
  370.  
  371.   use APR::Pool ();
  372.   sub ancestry_count {
  373.       my $child = shift;
  374.       my $gen = 0;
  375.       while (my $parent = $child->parent_get) {
  376.           $gen++;
  377.           $child = $parent;
  378.       }
  379.       return $gen;
  380.   }
  381.  
  382.  
  383.  
  384. =head2 C<tag>
  385.  
  386. Tag a pool (give it a name)
  387.  
  388.   $pool->tag($tag);
  389.  
  390. =over 4
  391.  
  392. =item obj: C<$pool> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  393.  
  394. The pool to tag
  395.  
  396. =item arg1: C<$tag> ( string )
  397.  
  398. The tag (some unique string)
  399.  
  400. =item ret: no return value
  401.  
  402. =item since: 1.99_12
  403.  
  404. =back
  405.  
  406. Each pool can be tagged with a unique label. This can prove useful
  407. when doing low level apr_pool C tracing (when apr is compiled with
  408. C<-DAPR_POOL_DEBUG>). It allows you to grep(1) for the tag you have
  409. set, to single out the traces relevant to you.
  410.  
  411. Though there is no way to get read the tag value, since APR doesn't
  412. provide such an accessor method.
  413.  
  414.  
  415.  
  416.  
  417.  
  418. =head1 Unsupported API
  419.  
  420. C<APR::Pool> also provides auto-generated Perl interface for a few
  421. other methods which aren't tested at the moment and therefore their
  422. API is a subject to change. These methods will be finalized later as a
  423. need arises. If you want to rely on any of the following methods
  424. please contact the L<the mod_perl development mailing
  425. list|maillist::dev> so we can help each other take the steps necessary
  426. to shift the method to an officially supported API.
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435. =head2 C<cleanup_for_exec>
  436.  
  437. META: Autogenerated - needs to be reviewed/completed
  438.  
  439. Preparing for exec() --- close files, etc., but *don't* flush I/O
  440. buffers, *don't* wait for subprocesses, and *don't* free any memory.
  441. Run all of the child_cleanups, so that any unnecessary files are
  442. closed because we are about to exec a new program
  443.  
  444. =over
  445.  
  446. =item ret: no return value
  447.  
  448. =item since: subject to change
  449.  
  450. =back
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458. =head1 See Also
  459.  
  460. L<mod_perl 2.0 documentation|docs::2.0::index>.
  461.  
  462.  
  463.  
  464.  
  465. =head1 Copyright
  466.  
  467. mod_perl 2.0 and its core modules are copyrighted under
  468. The Apache Software License, Version 2.0.
  469.  
  470.  
  471.  
  472.  
  473. =head1 Authors
  474.  
  475. L<The mod_perl development team and numerous
  476. contributors|about::contributors::people>.
  477.  
  478. =cut
  479.  
  480.