/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/api/APR/Table.html is in libapache2-mod-perl2-doc 2.0.8+httpd24-r1449661-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | <?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#Synopsis">Synopsis</a></li>
<li><a href="#Description">Description</a></li>
<li><a href="#API">API</a>
<ul>
<li><a href="#add">add</a></li>
<li><a href="#clear">clear</a></li>
<li><a href="#compress">compress</a></li>
<li><a href="#copy">copy</a></li>
<li><a href="#do">do</a></li>
<li><a href="#get">get</a></li>
<li><a href="#make">make</a></li>
<li><a href="#merge">merge</a></li>
<li><a href="#overlap">overlap</a></li>
<li><a href="#overlay">overlay</a></li>
<li><a href="#set">set</a></li>
<li><a href="#unset">unset</a></li>
</ul>
</li>
<li><a href="#TIE-Interface">TIE Interface</a>
<ul>
<li><a href="#EXISTS">EXISTS</a></li>
<li><a href="#CLEAR">CLEAR</a></li>
<li><a href="#STORE">STORE</a></li>
<li><a href="#DELETE">DELETE</a></li>
<li><a href="#FETCH">FETCH</a></li>
</ul>
</li>
<li><a href="#See-Also">See Also</a></li>
<li><a href="#Copyright">Copyright</a></li>
<li><a href="#Authors">Authors</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>APR::Table - Perl API for manipulating APR opaque string-content tables</p>
<h1 id="Synopsis">Synopsis</h1>
<pre><code> use APR::Table ();
$table = APR::Table::make($pool, $nelts);
$table_copy = $table->copy($pool);
$table->clear();
$table->set($key => $val);
$table->unset($key);
$table->add($key, $val);
$val = $table->get($key);
@val = $table->get($key);
$table->merge($key => $val);
use APR::Const -compile qw(:table);
$table_overlay = $table_base->overlay($table_overlay, $pool);
$table_overlay->compress(APR::Const::OVERLAP_TABLES_MERGE);
$table_a->overlap($table_b, APR::Const::OVERLAP_TABLES_SET);
$table->do(sub {print "key $_[0], value $_[1]\n"}, @valid_keys);
#Tied Interface
$value = $table->{$key};
$table->{$key} = $value;
print "got it" if exists $table->{$key};
foreach my $key (keys %{$table}) {
print "$key = $table->{$key}\n";
}</code></pre>
<h1 id="Description">Description</h1>
<p><code>APR::Table</code> allows its users to manipulate opaque string-content tables.</p>
<p>On the C level the "opaque string-content" means: you can put in '\0'-terminated strings and whatever you put in your get out.</p>
<p>On the Perl level that means that we convert scalars into strings and store those strings. Any special information that was in the Perl scalar is not stored. So for example if a scalar was marked as utf8, tainted or tied, that information is not stored. When you get the data back as a Perl scalar you get only the string.</p>
<p>The table's structure is somewhat similar to the Perl's hash structure, but allows multiple values for the same key. An access to the records stored in the table always requires a key.</p>
<p>The key-value pairs are stored in the order they are added.</p>
<p>The keys are case-insensitive.</p>
<p>However as of the current implementation if more than value for the same key is requested, the whole table is lineary searched, which is very inefficient unless the table is very small.</p>
<p><code>APR::Table</code> provides a <a href="#TIE_Interface">TIE Interface</a>.</p>
<p>See <i>apr/include/apr_tables.h</i> in ASF's <i>apr</i> project for low level details.</p>
<h1 id="API">API</h1>
<p><code>APR::Table</code> provides the following functions and/or methods:</p>
<h2 id="add"><code>add</code></h2>
<p>Add data to a table, regardless of whether there is another element with the same key.</p>
<pre><code> $table->add($key, $val);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to add to.</p>
</dd>
<dt id="arg1:-key-string">arg1: <code>$key</code> ( string )</dt>
<dd>
<p>The key to use.</p>
</dd>
<dt id="arg2:-val-string">arg2: <code>$val</code> ( string )</dt>
<dd>
<p>The value to add.</p>
</dd>
<dt id="ret:-no-return-value">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.00">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>When adding data, this function makes a copy of both the key and the value.</p>
<h2 id="clear"><code>clear</code></h2>
<p>Delete all of the elements from a table.</p>
<pre><code> $table->clear();</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object1">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to clear.</p>
</dd>
<dt id="ret:-no-return-value1">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.001">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="compress"><code>compress</code></h2>
<p>Eliminate redundant entries in a table by either overwriting or merging duplicates:</p>
<pre><code> $table->compress($flags);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object2">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to compress.</p>
</dd>
<dt id="arg1:-flags-APR::Const-constant">arg1: <code>$flags</code> (<code><a>APR::Const constant</a></code>)</dt>
<dd>
<pre><code> APR::Const::OVERLAP_TABLES_MERGE -- to merge
APR::Const::OVERLAP_TABLES_SET -- to overwrite</code></pre>
</dd>
<dt id="ret:-no-return-value2">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.002">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Converts multi-valued keys in <code>$table</code> into single-valued keys. This function takes duplicate table entries and flattens them into a single entry. The flattening behavior is controlled by the (mandatory) <code>$flags</code> argument.</p>
<p>When <code>$flags</code> == <code>APR::Const::OVERLAP_TABLES_SET</code>, each key will be set to the last value seen for that key. For example, given key/value pairs 'foo => bar' and 'foo => baz', 'foo' would have a final value of 'baz' after compression -- the 'bar' value would be lost.</p>
<p>When <code>$flags</code> == <code>APR::Const::OVERLAP_TABLES_MERGE</code>, multiple values for the same key are flattened into a comma-separated list. Given key/value pairs 'foo => bar' and 'foo => baz', 'foo' would have a final value of 'bar, baz' after compression.</p>
<p>Access the constants via:</p>
<pre><code> use APR::Const -compile qw(:table);</code></pre>
<p>or an explicit:</p>
<pre><code> use APR::Const -compile qw(OVERLAP_TABLES_SET OVERLAP_TABLES_MERGE);</code></pre>
<p><code>compress()</code> combined with <code><a href="#C_overlay_">overlay()</a></code> does the same thing as <code><a href="#C_overlap_">overlap()</a></code>.</p>
<p>Examples:</p>
<ul>
<li><p><code>APR::Const::OVERLAP_TABLES_SET</code></p>
<p>Start with table <code>$table</code>:</p>
<pre><code> foo => "one"
foo => "two"
foo => "three"
bar => "beer"</code></pre>
<p>which is done by:</p>
<pre><code> use APR::Const -compile => ':table';
my $table = APR::Table::make($r->pool, TABLE_SIZE);
$table->set(bar => 'beer');
$table->set(foo => 'one');
$table->add(foo => 'two');
$table->add(foo => 'three');</code></pre>
<p>Now compress it using <code>APR::Const::OVERLAP_TABLES_SET</code>:</p>
<pre><code> $table->compress(APR::Const::OVERLAP_TABLES_SET);</code></pre>
<p>Now table <code>$table</code> contains:</p>
<pre><code> foo => "three"
bar => "beer"</code></pre>
<p>The value <i>three</i> for the key <i>foo</i>, that was added last, took over the other values.</p>
</li>
<li><p><code>APR::Const::OVERLAP_TABLES_MERGE</code></p>
<p>Start with table <code>$table</code>:</p>
<pre><code> foo => "one"
foo => "two"
foo => "three"
bar => "beer"</code></pre>
<p>as in the previous example, now compress it using <code>APR::Const::OVERLAP_TABLES_MERGE</code>:</p>
<pre><code> $table->compress(APR::Const::OVERLAP_TABLES_MERGE);</code></pre>
<p>Now table <code>$table</code> contains:</p>
<pre><code> foo => "one, two, three"
bar => "beer"</code></pre>
<p>All the values for the same key were merged into one value.</p>
</li>
</ul>
<h2 id="copy"><code>copy</code></h2>
<p>Create a new table and copy another table into it.</p>
<pre><code> $table_copy = $table->copy($p);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object3">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to copy.</p>
</dd>
<dt id="arg1:-p-APR::Pool-object">arg1: <code>$p</code> ( <code><a>APR::Pool object</a></code> )</dt>
<dd>
<p>The pool to allocate the new table out of.</p>
</dd>
<dt id="ret:-table_copy-APR::Table-object">ret: <code>$table_copy</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>A copy of the table passed in.</p>
</dd>
<dt id="since:-2.0.003">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="do"><code>do</code></h2>
<p>Iterate over all the elements of the table, invoking provided subroutine for each element. The subroutine gets passed as argument, a key-value pair.</p>
<pre><code> $table->do(sub {...}, @filter);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object4">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to operate on.</p>
</dd>
<dt id="arg1:-sub-CODE-ref-string">arg1: <code>$sub</code> ( CODE ref/string )</dt>
<dd>
<p>A subroutine reference or name to be called on each item in the table. The subroutine can abort the iteration by returning 0 and should always return 1 otherwise.</p>
</dd>
<dt id="opt-arg3:-filter-ARRAY">opt arg3: <code>@filter</code> ( ARRAY )</dt>
<dd>
<p>If passed, only keys matching one of the entries in f<code>@filter</code> will be processed.</p>
</dd>
<dt id="ret:-no-return-value3">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.004">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Examples:</p>
<ul>
<li><p>This filter simply prints out the key/value pairs and counts how many pairs did it see.</p>
<pre><code> use constant TABLE_SIZE => 20;
our $filter_count;
my $table = APR::Table::make($r->pool, TABLE_SIZE);
# populate the table with ascii data
for (1..TABLE_SIZE) {
$table->set(chr($_+97), $_);
}
$filter_count = 0;
$table->do("my_filter");
print "Counted $filter_count elements";
sub my_filter {
my ($key, $value) = @_;
warn "$key => $value\n";
$filter_count++;
return 1;
}</code></pre>
<p>Notice that <code>my_filter</code> always returns 1, ensuring that <code>do()</code> will pass all the key/value pairs.</p>
</li>
<li><p>This filter is similar to the one from the previous example, but this time it decides to abort the filtering after seeing half of the table, by returning 0 when this happens.</p>
<pre><code> sub my_filter {
my ($key, $value) = @_;
$filter_count++;
return $filter_count == int(TABLE_SIZE)/2 ? 0 : 1;
}</code></pre>
</li>
</ul>
<h2 id="get"><code>get</code></h2>
<p>Get the value(s) associated with a given key. After this call, the data is still in the table.</p>
<pre><code> $val = $table->get($key);
@val = $table->get($key);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object5">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to search for the key.</p>
</dd>
<dt id="arg1:-key-string1">arg1: <code>$key</code> ( string )</dt>
<dd>
<p>The key to search for.</p>
</dd>
<dt id="ret:-val-or-val">ret: <code>$val</code> or <code>@val</code></dt>
<dd>
<p>In the scalar context the first matching value returned (the oldest in the table, if there is more than one value). If nothing matches <code>undef</code> is returned.</p>
<p>In the list context the whole table is traversed and all matching values are returned. An empty list is returned if nothing matches.</p>
</dd>
<dt id="since:-2.0.005">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="make"><code>make</code></h2>
<p>Make a new table.</p>
<pre><code> $table = APR::Table::make($p, $nelts);</code></pre>
<dl>
<dt id="obj:-p-APR::Pool-object">obj: <code>$p</code> ( <code><a>APR::Pool object</a></code> )</dt>
<dd>
<p>The pool to allocate the pool out of.</p>
</dd>
<dt id="arg1:-nelts-integer">arg1: <code>$nelts</code> ( integer )</dt>
<dd>
<p>The number of elements in the initial table. At least 1 or more. If 0 is passed APR will still allocate 1.</p>
</dd>
<dt id="ret:-table-APR::Table-object">ret: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The new table.</p>
</dd>
<dt id="since:-2.0.006">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>This table can only store text data.</p>
<h2 id="merge"><code>merge</code></h2>
<p>Add data to a table by merging the value with data that has already been stored using ", " as a separator:</p>
<pre><code> $table->merge($key, $val);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object6">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to search for the data.</p>
</dd>
<dt id="arg1:-key-string2">arg1: <code>$key</code> ( string )</dt>
<dd>
<p>The key to merge data for.</p>
</dd>
<dt id="arg2:-val-string1">arg2: <code>$val</code> ( string )</dt>
<dd>
<p>The data to add.</p>
</dd>
<dt id="ret:-no-return-value4">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.007">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>If the key is not found, then this function acts like <code><a href="#C_add_">add()</a></code>.</p>
<p>If there is more than one value for the same key, only the first (the oldest) value gets merged.</p>
<p>Examples:</p>
<ul>
<li><p>Start with a pair:</p>
<pre><code> merge => "1"</code></pre>
<p>and merge "a" to the value:</p>
<pre><code> $table->set( merge => '1');
$table->merge(merge => 'a');
$val = $table->get('merge');</code></pre>
<p>Result:</p>
<pre><code> $val == "1, a";</code></pre>
</li>
<li><p>Start with a multivalued pair:</p>
<pre><code> merge => "1"
merge => "2"</code></pre>
<p>and merge "a" to the first value;</p>
<pre><code> $table->set( merge => '1');
$table->add( merge => '2');
$table->merge(merge => 'a');
@val = $table->get('merge');</code></pre>
<p>Result:</p>
<pre><code> $val[0] == "1, a";
$val[1] == "2";</code></pre>
<p>Only the first value for the same key is affected.</p>
</li>
<li><p>Have no entry and merge "a";</p>
<pre><code> $table->merge(miss => 'a');
$val = $table->get('miss');</code></pre>
<p>Result:</p>
<pre><code> $val == "a";</code></pre>
</li>
</ul>
<h2 id="overlap"><code>overlap</code></h2>
<p>For each key/value pair in <code>$table_b</code>, add the data to <code>$table_a</code>. The definition of <code>$flags</code> explains how <code>$flags</code> define the overlapping method.</p>
<pre><code> $table_a->overlap($table_b, $flags);</code></pre>
<dl>
<dt id="obj:-table_a-APR::Table-object">obj: <code>$table_a</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to add the data to.</p>
</dd>
<dt id="arg1:-table_b-APR::Table-object">arg1: <code>$table_b</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to iterate over, adding its data to table <code>$table_a</code></p>
</dd>
<dt id="arg2:-flags-integer">arg2: <code>$flags</code> ( integer )</dt>
<dd>
<p>How to add the table to table <code>$table_a</code>.</p>
<p>When <code>$flags</code> == <code>APR::Const::OVERLAP_TABLES_SET</code>, if another element already exists with the same key, this will over-write the old data.</p>
<p>When <code>$flags</code> == <code>APR::Const::OVERLAP_TABLES_MERGE</code>, the key/value pair from <code>$table_b</code> is added, regardless of whether there is another element with the same key in <code>$table_a</code>.</p>
</dd>
<dt id="ret:-no-return-value5">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.008">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Access the constants via:</p>
<pre><code> use APR::Const -compile qw(:table);</code></pre>
<p>or an explicit:</p>
<pre><code> use APR::Const -compile qw(OVERLAP_TABLES_SET OVERLAP_TABLES_MERGE);</code></pre>
<p>This function is highly optimized, and uses less memory and CPU cycles than a function that just loops through table <code>$table_b</code> calling other functions.</p>
<p>Conceptually, <code>overlap()</code> does this:</p>
<pre><code> apr_array_header_t *barr = apr_table_elts(b);
apr_table_entry_t *belt = (apr_table_entry_t *)barr-E<gt>elts;
int i;
for (i = 0; i < barr->nelts; ++i) {
if (flags & APR_OVERLAP_TABLES_MERGE) {
apr_table_mergen(a, belt[i].key, belt[i].val);
}
else {
apr_table_setn(a, belt[i].key, belt[i].val);
}
}</code></pre>
<p>Except that it is more efficient (less space and cpu-time) especially when <code>$table_b</code> has many elements.</p>
<p>Notice the assumptions on the keys and values in <code>$table_b</code> -- they must be in an ancestor of <code>$table_a</code>'s pool. In practice <code>$table_b</code> and <code>$table_a</code> are usually from the same pool.</p>
<p>Examples:</p>
<ul>
<li><p><code>APR::Const::OVERLAP_TABLES_SET</code></p>
<p>Start with table <code>$base</code>:</p>
<pre><code> foo => "one"
foo => "two"
bar => "beer"</code></pre>
<p>and table <code>$add</code>:</p>
<pre><code> foo => "three"</code></pre>
<p>which is done by:</p>
<pre><code> use APR::Const -compile => ':table';
my $base = APR::Table::make($r->pool, TABLE_SIZE);
my $add = APR::Table::make($r->pool, TABLE_SIZE);
$base->set(bar => 'beer');
$base->set(foo => 'one');
$base->add(foo => 'two');
$add->set(foo => 'three');</code></pre>
<p>Now overlap using <code>APR::Const::OVERLAP_TABLES_SET</code>:</p>
<pre><code> $base->overlap($add, APR::Const::OVERLAP_TABLES_SET);</code></pre>
<p>Now table <code>$add</code> is unmodified and table <code>$base</code> contains:</p>
<pre><code> foo => "three"
bar => "beer"</code></pre>
<p>The value from table <code>add</code> has overwritten all previous values for the same key both had (<i>foo</i>). This is the same as doing <code><a href="#C_overlay_">overlay()</a></code> followed by <code><a href="#C_compress_">compress()</a></code> with <code>APR::Const::OVERLAP_TABLES_SET</code>.</p>
</li>
<li><p><code>APR::Const::OVERLAP_TABLES_MERGE</code></p>
<p>Start with table <code>$base</code>:</p>
<pre><code> foo => "one"
foo => "two"</code></pre>
<p>and table <code>$add</code>:</p>
<pre><code> foo => "three"
bar => "beer"</code></pre>
<p>which is done by:</p>
<pre><code> use APR::Const -compile => ':table';
my $base = APR::Table::make($r->pool, TABLE_SIZE);
my $add = APR::Table::make($r->pool, TABLE_SIZE);
$base->set(foo => 'one');
$base->add(foo => 'two');
$add->set(foo => 'three');
$add->set(bar => 'beer');</code></pre>
<p>Now overlap using <code>APR::Const::OVERLAP_TABLES_MERGE</code>:</p>
<pre><code> $base->overlap($add, APR::Const::OVERLAP_TABLES_MERGE);</code></pre>
<p>Now table <code>$add</code> is unmodified and table <code>$base</code> contains:</p>
<pre><code> foo => "one, two, three"
bar => "beer"</code></pre>
<p>Values from both tables for the same key were merged into one value. This is the same as doing <code><a href="#C_overlay_">overlay()</a></code> followed by <code><a href="#C_compress_">compress()</a></code> with <code>APR::Const::OVERLAP_TABLES_MERGE</code>.</p>
</li>
</ul>
<h2 id="overlay"><code>overlay</code></h2>
<p>Merge two tables into one new table. The resulting table may have more than one value for the same key.</p>
<pre><code> $table = $table_base->overlay($table_overlay, $p);</code></pre>
<dl>
<dt id="obj:-table_base-APR::Table-object">obj: <code>$table_base</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to add at the end of the new table.</p>
</dd>
<dt id="arg1:-table_overlay-APR::Table-object">arg1: <code>$table_overlay</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The first table to put in the new table.</p>
</dd>
<dt id="arg2:-p-APR::Pool-object">arg2: <code>$p</code> ( <code><a>APR::Pool object</a></code> )</dt>
<dd>
<p>The pool to use for the new table.</p>
</dd>
<dt id="ret:-table-APR::Table-object1">ret: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>A new table containing all of the data from the two passed in.</p>
</dd>
<dt id="since:-2.0.009">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Examples:</p>
<ul>
<li><p>Start with table <code>$base</code>:</p>
<pre><code> foo => "one"
foo => "two"
bar => "beer"</code></pre>
<p>and table <code>$add</code>:</p>
<pre><code> foo => "three"</code></pre>
<p>which is done by:</p>
<pre><code> use APR::Const -compile => ':table';
my $base = APR::Table::make($r->pool, TABLE_SIZE);
my $add = APR::Table::make($r->pool, TABLE_SIZE);
$base->set(bar => 'beer');
$base->set(foo => 'one');
$base->add(foo => 'two');
$add->set(foo => 'three');</code></pre>
<p>Now overlay using <code>APR::Const::OVERLAP_TABLES_SET</code>:</p>
<pre><code> my $overlay = $base->overlay($add, APR::Const::OVERLAP_TABLES_SET);</code></pre>
<p>That resulted in a new table <code>$overlay</code> (tables <code>add</code> and <code>$base</code> are unmodified) which contains:</p>
<pre><code> foo => "one"
foo => "two"
foo => "three"
bar => "beer"</code></pre>
</li>
</ul>
<h2 id="set"><code>set</code></h2>
<p>Add a key/value pair to a table, if another element already exists with the same key, this will over-write the old data.</p>
<pre><code> $table->set($key, $val);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object7">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to add the data to.</p>
</dd>
<dt id="arg1:-key-string3">arg1: <code>$key</code> ( string )</dt>
<dd>
<p>The key to use.</p>
</dd>
<dt id="arg2:-val-string2">arg2: <code>$val</code> ( string )</dt>
<dd>
<p>The value to add.</p>
</dd>
<dt id="ret:-no-return-value6">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0010">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>When adding data, this function makes a copy of both the key and the value.</p>
<h2 id="unset"><code>unset</code></h2>
<p>Remove data from the table.</p>
<pre><code> $table->unset($key);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object8">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
<p>The table to remove data from.</p>
</dd>
<dt id="arg1:-key-string4">arg1: <code>$key</code> ( string )</dt>
<dd>
<p>The key of the data being removed.</p>
</dd>
<dt id="ret:-no-return-value7">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0011">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h1 id="TIE-Interface">TIE Interface</h1>
<p><code>APR::Table</code> also implements a tied interface, so you can work with the <code>$table</code> object as a hash reference.</p>
<p>The following tied-hash function are supported: <code>FETCH</code>, <code>STORE</code>, <code>DELETE</code>, <code>CLEAR</code>, <code>EXISTS</code>, <code>FIRSTKEY</code>, <code>NEXTKEY</code> and <code>DESTROY</code>.</p>
<p>Note regarding the use of <code>values()</code>. <code>APR::Table</code> can hold more than one key-value pair sharing the same key, so when using a table through the tied interface, the first entry found with the right key will be used, completely disregarding possible other entries with the same key. With Perl 5.8.0 and higher <code>values()</code> will correctly list values the corresponding to the list generated by <code>keys()</code>. That doesn't work with Perl 5.6. Therefore to portably iterate over the key-value pairs, use <code>each()</code> (which fully supports multivalued keys), or <code>APR::Table::do</code>.</p>
<h2 id="EXISTS"><code>EXISTS</code></h2>
<pre><code> $ret = $table->EXISTS($key);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object9">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-key-string5">arg1: <code>$key</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-ret-integer">ret: <code>$ret</code> ( integer )</dt>
<dd>
<p>true or false</p>
</dd>
<dt id="since:-2.0.0012">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="CLEAR"><code>CLEAR</code></h2>
<pre><code> $table->CLEAR();</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object10">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
</dd>
<dt id="ret:-no-return-value8">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0013">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="STORE"><code>STORE</code></h2>
<pre><code> $table->STORE($key, $val);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object11">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-key-string6">arg1: <code>$key</code> ( string )</dt>
<dd>
</dd>
<dt id="arg2:-val-string3">arg2: <code>$val</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-no-return-value9">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0014">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="DELETE"><code>DELETE</code></h2>
<pre><code> $table->DELETE($key);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object12">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-key-string7">arg1: <code>$key</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-no-return-value10">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0015">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="FETCH"><code>FETCH</code></h2>
<pre><code> $ret = $table->FETCH($key);</code></pre>
<dl>
<dt id="obj:-table-APR::Table-object13">obj: <code>$table</code> ( <code><a>APR::Table object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-key-string8">arg1: <code>$key</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-ret-string">ret: <code>$ret</code> ( string )</dt>
<dd>
</dd>
<dt id="since:-2.0.0016">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>When iterating through the table's entries with <code>each()</code>, <code>FETCH</code> will return the current value of a multivalued key. For example:</p>
<pre><code> $table->add("a" => 1);
$table->add("b" => 2);
$table->add("a" => 3);
($k, $v) = each %$table; # (a, 1)
print $table->{a}; # prints 1
($k, $v) = each %$table; # (b, 2)
print $table->{a}; # prints 1
($k, $v) = each %$table; # (a, 3)
print $table->{a}; # prints 3 !!!
($k, $v) = each %$table; # (undef, undef)
print $table->{a}; # prints 1</code></pre>
<h1 id="See-Also">See Also</h1>
<p><a>mod_perl 2.0 documentation</a>.</p>
<h1 id="Copyright">Copyright</h1>
<p>mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.</p>
<h1 id="Authors">Authors</h1>
<p><a>The mod_perl development team and numerous contributors</a>.</p>
</body>
</html>
|