/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/user/porting/compat.html is in libapache2-mod-perl2-doc 2.0.9~1624218-2+deb8u2.
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 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | <?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>
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#Description">Description</a></li>
<li><a href="#Configuration-Files-Porting">Configuration Files Porting</a>
<ul>
<li><a href="#PerlHandler">PerlHandler</a></li>
<li><a href="#PerlScript">PerlScript</a></li>
<li><a href="#PerlSendHeader">PerlSendHeader</a></li>
<li><a href="#PerlSetupEnv">PerlSetupEnv</a></li>
<li><a href="#PerlTaintCheck">PerlTaintCheck</a></li>
<li><a href="#PerlWarn">PerlWarn</a></li>
<li><a href="#PerlFreshRestart">PerlFreshRestart</a></li>
<li><a href="#Apache::Server::StrictPerlSections">$Apache::Server::StrictPerlSections</a></li>
<li><a href="#Apache::Server::SaveConfig">$Apache::Server::SaveConfig</a></li>
<li><a href="#Apache-Configuration-Customization">Apache Configuration Customization</a></li>
<li><a href="#INC-Manipulation">@INC Manipulation</a></li>
</ul>
</li>
<li><a href="#Server-Startup">Server Startup</a></li>
<li><a href="#Code-Porting">Code Porting</a></li>
<li><a href="#Apache::Registry-Apache::PerlRun-and-Friends">Apache::Registry, Apache::PerlRun and Friends</a>
<ul>
<li><a href="#ModPerl::RegistryLoader">ModPerl::RegistryLoader</a></li>
</ul>
</li>
<li><a href="#Apache::Constants">Apache::Constants</a>
<ul>
<li><a href="#mod_perl-1.0-and-2.0-Constants-Coexistence">mod_perl 1.0 and 2.0 Constants Coexistence</a></li>
<li><a href="#Deprecated-Constants">Deprecated Constants</a></li>
<li><a href="#SERVER_VERSION">SERVER_VERSION()</a></li>
<li><a href="#export">export()</a></li>
</ul>
</li>
<li><a href="#Issues-with-Environment-Variables">Issues with Environment Variables</a></li>
<li><a href="#Special-Environment-Variables">Special Environment Variables</a>
<ul>
<li><a href="#ENV-GATEWAY_INTERFACE">$ENV{GATEWAY_INTERFACE}</a></li>
</ul>
</li>
<li><a href="#Apache::-Methods">Apache:: Methods</a>
<ul>
<li><a href="#Apache-request">Apache->request</a></li>
<li><a href="#Apache-define">Apache->define</a></li>
<li><a href="#Apache-can_stack_handlers">Apache->can_stack_handlers</a></li>
<li><a href="#Apache-untaint">Apache->untaint</a></li>
<li><a href="#Apache-get_handlers">Apache->get_handlers</a></li>
<li><a href="#Apache-push_handlers">Apache->push_handlers</a></li>
<li><a href="#Apache-set_handlers">Apache->set_handlers</a></li>
<li><a href="#Apache-httpd_conf">Apache->httpd_conf</a></li>
<li><a href="#Apache-unescape_url_info">Apache->unescape_url_info</a></li>
<li><a href="#Apache::exit">Apache::exit()</a></li>
<li><a href="#Apache::gensym">Apache::gensym()</a></li>
<li><a href="#Apache::log_error">Apache::log_error()</a></li>
<li><a href="#Apache-warn">Apache->warn</a></li>
<li><a href="#Apache::warn">Apache::warn</a></li>
<li><a href="#Apache::module">Apache::module()</a></li>
</ul>
</li>
<li><a href="#Apache::-Variables">Apache:: Variables</a>
<ul>
<li><a href="#Apache::__T">$Apache::__T</a></li>
</ul>
</li>
<li><a href="#Apache::Module::-Methods">Apache::Module:: Methods</a>
<ul>
<li><a href="#Apache::Module-top_module">Apache::Module->top_module</a></li>
<li><a href="#Apache::Module-get_config">Apache::Module->get_config</a></li>
</ul>
</li>
<li><a href="#Apache::ModuleConfig::-Methods">Apache::ModuleConfig:: Methods</a>
<ul>
<li><a href="#Apache::ModuleConfig-get">Apache::ModuleConfig->get</a></li>
</ul>
</li>
<li><a href="#Apache::Server::-Methods-and-Variables">Apache::Server:: Methods and Variables</a>
<ul>
<li><a href="#Apache::Server::CWD">$Apache::Server::CWD</a></li>
<li><a href="#Apache::Server::AddPerlVersion">$Apache::Server::AddPerlVersion</a></li>
<li><a href="#Apache::Server::Starting-and-Apache::Server::ReStarting">$Apache::Server::Starting and $Apache::Server::ReStarting</a></li>
<li><a href="#Apache::Server-warn">Apache::Server->warn</a></li>
</ul>
</li>
<li><a href="#Server-Object-Methods">Server Object Methods</a>
<ul>
<li><a href="#s-register_cleanup">$s->register_cleanup</a></li>
<li><a href="#s-uid">$s->uid</a></li>
<li><a href="#s-gid">$s->gid</a></li>
</ul>
</li>
<li><a href="#Request-Object-Methods">Request Object Methods</a>
<ul>
<li><a href="#r-print">$r->print</a></li>
<li><a href="#r-cgi_env">$r->cgi_env</a></li>
<li><a href="#r-cgi_var">$r->cgi_var</a></li>
<li><a href="#r-current_callback">$r->current_callback</a></li>
<li><a href="#r-cleanup_for_exec">$r->cleanup_for_exec</a></li>
<li><a href="#r-get_remote_host">$r->get_remote_host</a></li>
<li><a href="#r-content">$r->content</a></li>
<li><a href="#r-args-in-an-Array-Context">$r->args in an Array Context</a></li>
<li><a href="#r-chdir_file">$r->chdir_file</a></li>
<li><a href="#r-is_main">$r->is_main</a></li>
<li><a href="#r-filename">$r->filename</a></li>
<li><a href="#r-finfo">$r->finfo</a></li>
<li><a href="#r-notes">$r->notes</a></li>
<li><a href="#r-header_in">$r->header_in</a></li>
<li><a href="#r-header_out">$r->header_out</a></li>
<li><a href="#r-err_header_out">$r->err_header_out</a></li>
<li><a href="#r-register_cleanup">$r->register_cleanup</a></li>
<li><a href="#r-post_connection">$r->post_connection</a></li>
<li><a href="#r-request">$r->request</a></li>
<li><a href="#r-send_fd">$r->send_fd</a></li>
<li><a href="#r-send_http_header">$r->send_http_header</a></li>
<li><a href="#r-server_root_relative">$r->server_root_relative</a></li>
<li><a href="#r-hard_timeout">$r->hard_timeout</a></li>
<li><a href="#r-reset_timeout">$r->reset_timeout</a></li>
<li><a href="#r-soft_timeout">$r->soft_timeout</a></li>
<li><a href="#r-kill_timeout">$r->kill_timeout</a></li>
<li><a href="#r-set_byterange">$r->set_byterange</a></li>
<li><a href="#r-each_byterange">$r->each_byterange</a></li>
</ul>
</li>
<li><a href="#Apache::Connection">Apache::Connection</a>
<ul>
<li><a href="#connection-auth_type">$connection->auth_type</a></li>
<li><a href="#connection-user">$connection->user</a></li>
<li><a href="#connection-local_addr">$connection->local_addr</a></li>
<li><a href="#connection-remote_addr">$connection->remote_addr</a></li>
</ul>
</li>
<li><a href="#Apache::File">Apache::File</a>
<ul>
<li><a href="#new-open-and-close">new(), open() and close()</a></li>
<li><a href="#tmpfile">tmpfile()</a></li>
</ul>
</li>
<li><a href="#Apache::Util">Apache::Util</a>
<ul>
<li><a href="#Apache::Util::size_string">Apache::Util::size_string()</a></li>
<li><a href="#Apache::Util::escape_uri">Apache::Util::escape_uri()</a></li>
<li><a href="#Apache::Util::unescape_uri">Apache::Util::unescape_uri()</a></li>
<li><a href="#Apache::Util::escape_html">Apache::Util::escape_html()</a></li>
<li><a href="#Apache::Util::parsedate">Apache::Util::parsedate()</a></li>
<li><a href="#Apache::Util::ht_time">Apache::Util::ht_time()</a></li>
<li><a href="#Apache::Util::validate_password">Apache::Util::validate_password()</a></li>
</ul>
</li>
<li><a href="#Apache::URI">Apache::URI</a>
<ul>
<li><a href="#Apache::URI-parse-r-uri">Apache::URI->parse($r, [$uri])</a></li>
<li><a href="#unparse">unparse()</a></li>
</ul>
</li>
<li><a href="#Miscellaneous">Miscellaneous</a>
<ul>
<li><a href="#Method-Handlers">Method Handlers</a></li>
<li><a href="#Stacked-Handlers">Stacked Handlers</a></li>
</ul>
</li>
<li><a href="#Apache::src">Apache::src</a></li>
<li><a href="#Apache::Table">Apache::Table</a></li>
<li><a href="#Apache::SIG">Apache::SIG</a></li>
<li><a href="#Apache::StatINC">Apache::StatINC</a></li>
<li><a href="#Maintainers">Maintainers</a></li>
<li><a href="#Authors">Authors</a></li>
<li><a href="#POD-ERRORS">POD ERRORS</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>A Reference to mod_perl 1.0 to mod_perl 2.0 Migration.</p>
<h1 id="Description">Description</h1>
<p>This chapter is a reference for porting code and configuration files from mod_perl 1.0 to mod_perl 2.0.</p>
<p>To learn about the porting process you should first read about <a>porting Perl modules</a> (and may be about <a>porting XS modules</a>).</p>
<p>As it will be explained in details later, loading <code><a>Apache2::compat</a></code> at the server startup, should make the code running properly under 1.0 work under mod_perl 2.0. If you want to port your code to mod_perl 2.0 or writing from scratch and not concerned about backwards compatibility, this document explains what has changed compared to <a>mod_perl 1.0</a>.</p>
<p>Several configuration directives were changed, renamed or removed. Several APIs have changed, renamed, removed, or moved to new packages. Certain functions while staying <a>exactly the same</a> as in mod_perl 1.0, now reside in different packages. Before using them you need to find out those packages and load them.</p>
<p>You should be able to find the destiny of the functions that you cannot find any more or which behave differently now under the package names the functions belong in mod_perl 1.0.</p>
<h1 id="Configuration-Files-Porting">Configuration Files Porting</h1>
<p>To migrate the configuration files to the mod_perl 2.0 syntax, you may need to do certain adjustments. Several configuration directives are deprecated in 2.0, but still available for backwards compatibility with mod_perl 1.0 unless 2.0 was built with <code><a>MP_COMPAT_1X=0</a></code>. If you don't need the backwards compatibility consider using the directives that have replaced them.</p>
<h2 id="PerlHandler"><code>PerlHandler</code></h2>
<p><code>PerlHandler</code> was replaced with <code><a>PerlResponseHandler</a></code>.</p>
<h2 id="PerlScript"><code>PerlScript</code></h2>
<p><code>PerlScript</code> was replaced with <code><a>PerlRequire</a></code>. <code>PerlRequire</code> is available in mod_perl 1.0, since 1997.</p>
<h2 id="PerlSendHeader"><code>PerlSendHeader</code></h2>
<p><code>PerlSendHeader</code> was replaced with <code><a>PerlOptions +/-ParseHeaders</a></code> directive.</p>
<pre><code> PerlSendHeader On => PerlOptions +ParseHeaders
PerlSendHeader Off => PerlOptions -ParseHeaders</code></pre>
<h2 id="PerlSetupEnv"><code>PerlSetupEnv</code></h2>
<p><code>PerlSetupEnv</code> was replaced with <code><a>PerlOptions +/-SetupEnv</a></code> directive.</p>
<pre><code> PerlSetupEnv On => PerlOptions +SetupEnv
PerlSetupEnv Off => PerlOptions -SetupEnv</code></pre>
<h2 id="PerlTaintCheck"><code>PerlTaintCheck</code></h2>
<p>The taint mode now can be turned on with <code><a>PerlSwitches</a></code>:</p>
<pre><code> PerlSwitches -T</code></pre>
<p>As with standard Perl, by default the taint mode is disabled and once enabled cannot be turned off inside the code.</p>
<h2 id="PerlWarn"><code>PerlWarn</code></h2>
<p>Warnings now can be enabled globally with <code><a>PerlSwitches</a></code>:</p>
<pre><code> PerlSwitches -w</code></pre>
<h2 id="PerlFreshRestart"><code>PerlFreshRestart</code></h2>
<p><code>PerlFreshRestart</code> is a mod_perl 1.0 legacy and doesn't exist in mod_perl 2.0. A full teardown and startup of interpreters is done on restart.</p>
<p>If you need to use the same <i>httpd.conf</i> for 1.0 and 2.0, use:</p>
<pre><code> <IfDefine !MODPERL2>
PerlFreshRestart
</IfDefine></code></pre>
<h2 id="Apache::Server::StrictPerlSections"><code>$Apache::Server::StrictPerlSections</code></h2>
<p>In mod_perl 2.0, <code><a><Perl> sections</a></code> errors are now always fatal. Any error in them will cause an immediate server startup abort, dumping the error to STDERR. To avoid this, <code>eval {}</code> can be used to trap errors and ignore them. In mod_perl 1.0, <code>strict</code> was somewhat of a misnomer.</p>
<h2 id="Apache::Server::SaveConfig"><code>$Apache::Server::SaveConfig</code></h2>
<p><code>$Apache::Server::SaveConfig</code> has been renamed to <code>$Apache2::PerlSections::Save</code>. see <code><a><Perl> sections</a></code> for more information on this global variable.</p>
<h2 id="Apache-Configuration-Customization">Apache Configuration Customization</h2>
<p>mod_perl 2.0 has slightly changed the mechanism for <a>adding custom configuration directives</a> and now also makes it easy to access an Apache parsed configuration tree's values.</p>
<p>META: add L<> to the config tree access when it'll be written.</p>
<h2 id="INC-Manipulation"><code>@INC</code> Manipulation</h2>
<ul>
<li><p>Directories Added Automatically to <code>@INC</code></p>
<p>Only if mod_perl was built with <code>MP_COMPAT_1X=1</code>, two directories: <i>$ServerRoot</i> and <i>$ServerRoot/lib/perl</i> are pushed onto <code>@INC</code>. <i>$ServerRoot</i> is as defined by the <code>ServerRoot</code> directive in <i>httpd.conf</i>.</p>
</li>
<li><p><code>PERL5LIB</code> and <code>PERLLIB</code> Environment Variables</p>
<p>mod_perl 2.0 doesn't do anything special about <code>PERL5LIB</code> and <code>PERLLIB</code> Environment Variables. If <code>-T</code> is in effect these variables are ignored by Perl. There are <a>several other ways</a> to adjust <code>@INC</code>.</p>
</li>
</ul>
<h1 id="Server-Startup">Server Startup</h1>
<p>mod_perl 1.0 was always running its startup code as soon as it was encountered. In mod_perl 2.0, it is not always the case. Refer to the <a>mod_perl 2.0 startup process section</a> for details.</p>
<h1 id="Code-Porting">Code Porting</h1>
<p>mod_perl 2.0 is trying hard to be back compatible with mod_perl 1.0. However some things (mostly APIs) have been changed. In order to gain a complete compatibilty with 1.0 while running under 2.0, you should load the compatibility module as early as possible:</p>
<pre><code> use Apache2::compat;</code></pre>
<p>at the server startup. And unless there are forgotten things or bugs, your code should work without any changes under 2.0 series.</p>
<p>However, unless you want to keep the 1.0 compatibility, you should try to remove the compatibility layer and adjust your code to work under 2.0 without it. You want to do it mainly for the performance improvement.</p>
<p>This document explains what APIs have changed and what new APIs should be used instead.</p>
<p>Finally, mod_perl 2.0 has all its methods spread across many modules. In order to use these methods the modules containing them have to be loaded first. The module <code><a>ModPerl::MethodLookup</a></code> can be used to find out which modules need to be used. This module also provides a function <code><a>preload_all_modules()</a></code> that will load all mod_perl 2.0 modules, implementing their API in XS, which is useful when one starts to port their mod_perl 1.0 code, though preferrably avoided in the production environment if you want to save memory.</p>
<h1 id="Apache::Registry-Apache::PerlRun-and-Friends"><code>Apache::Registry</code>, <code>Apache::PerlRun</code> and Friends</h1>
<p><code>Apache::Registry</code>, <code>Apache::PerlRun</code> and other modules from the registry family now live in the <code>ModPerl::</code> namespace. In mod_perl 2.0 we put mod_perl specific functionality into the <code>ModPerl::</code> namespace, similar to <code>APR::</code> and <code>Apache2::</code> which are used for libapr and Apache, respectively.</p>
<p><code><a>ModPerl::Registry</a></code> (and others) doesn't <code>chdir()</code> into the script's dir like <code>Apache::Registry</code> does, because <code>chdir()</code> affects the whole process under threads. If you need this functionality use <code><a>ModPerl::RegistryPrefork</a></code> or <code><a>ModPerl::PerlRunPrefork</a></code>.</p>
<p>Otherwise <code>ModPerl::Registry</code> modules are configured and used similarly to <code>Apache::Registry</code> modules. Refer to one of the following manpages for more information: <code><a>ModPerl::RegistryCooker</a></code>, <code><a>ModPerl::Registry</a></code>, <code><a>ModPerl::RegistryBB</a></code> and <code><a>ModPerl::PerlRun</a></code>.</p>
<h2 id="ModPerl::RegistryLoader"><code>ModPerl::RegistryLoader</code></h2>
<p>In mod_perl 1.0 it was only possible to preload scripts as <code>Apache::Registry</code> handlers. In 2.0 the loader can use any of the registry classes to preload into. The old API works as before, but new options can be passed. See the <code><a>ModPerl::RegistryLoader</a></code> manpage for more information.</p>
<h1 id="Apache::Constants"><code>Apache::Constants</code></h1>
<p><code>Apache::Constants</code> has been replaced by three classes:</p>
<dl>
<dt id="Apache2::Const"><code><a>Apache2::Const</a></code></dt>
<dd>
<p>Apache constants</p>
</dd>
<dt id="APR::Const"><code><a>APR::Const</a></code></dt>
<dd>
<p>Apache Portable Runtime constants</p>
</dd>
<dt id="ModPerl::Const"><code><a>ModPerl::Const</a></code></dt>
<dd>
<p>mod_perl specific constants</p>
</dd>
</dl>
<p>See the manpages of the respective modules to figure out which constants they provide.</p>
<p>META: add the info how to perform the transition. XXX: may be write a script, which can tell you how to port the constants to 2.0? Currently <code><a>Apache2::compat</a></code> doesn't provide a complete back compatibility layer.</p>
<h2 id="mod_perl-1.0-and-2.0-Constants-Coexistence">mod_perl 1.0 and 2.0 Constants Coexistence</h2>
<p>If the same codebase is used for both mod_perl generations, the following technique can be used for using constants:</p>
<pre><code> package MyApache2::Foo;
use strict;
use warnings;
use mod_perl;
use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and
$ENV{MOD_PERL_API_VERSION} >= 2 );
BEGIN {
if (MP2) {
require Apache2::Const;
Apache2::Const->import(-compile => qw(OK DECLINED));
}
else {
require Apache::Constants;
Apache::Constants->import(qw(OK DECLINED));
}
}
sub handler {
# ...
return MP2 ? Apache2::Const::OK : Apache::Constants::OK;
}
1;</code></pre>
<p>Notice that if you don't use the idiom:</p>
<pre><code> return MP2 ? Apache2::Const::OK : Apache::Constants::OK;</code></pre>
<p>but something like the following:</p>
<pre><code> sub handler1 {
...
return Apache::Constants::OK();
}
sub handler2 {
...
return Apache2::Const::OK();
}</code></pre>
<p>You need to add <code>()</code>. If you don't do that, let's say that you run under mod_perl 2.0, perl will complain about mod_perl 1.0 constant:</p>
<pre><code> Bareword "Apache::Constants::OK" not allowed while "strict subs" ...</code></pre>
<p>Adding <code>()</code> prevents this warning.</p>
<h2 id="Deprecated-Constants">Deprecated Constants</h2>
<p><code>REDIRECT</code> and similar constants have been deprecated in Apache for years, in favor of the <code>HTTP_*</code> names (they no longer exist Apache 2.0). mod_perl 2.0 API performs the following aliasing behind the scenes:</p>
<pre><code> NOT_FOUND => 'HTTP_NOT_FOUND',
FORBIDDEN => 'HTTP_FORBIDDEN',
AUTH_REQUIRED => 'HTTP_UNAUTHORIZED',
SERVER_ERROR => 'HTTP_INTERNAL_SERVER_ERROR',
REDIRECT => 'HTTP_MOVED_TEMPORARILY',</code></pre>
<p>but we suggest moving to use the <code>HTTP_*</code> names. For example if running in mod_perl 1.0 compatibility mode, change:</p>
<pre><code> use Apache::Constants qw(REDIRECT);</code></pre>
<p>to:</p>
<pre><code> use Apache::Constants qw(HTTP_MOVED_TEMPORARILY);</code></pre>
<p>This will work in both mod_perl generations.</p>
<h2 id="SERVER_VERSION"><code>SERVER_VERSION()</code></h2>
<p><code>Apache::Constants::SERVER_VERSION()</code> has been replaced with <code><a>Apache2::ServerUtil::get_server_version()</a></code>.</p>
<h2 id="export"><code>export()</code></h2>
<p><code>Apache::Constants::export()</code> has no replacement in 2.0 as it's not needed.</p>
<h1 id="Issues-with-Environment-Variables">Issues with Environment Variables</h1>
<p>There are several thread-safety issues with setting environment variables.</p>
<p>Environment variables set during request time won't be seen by C code. See the <a>DBD::Oracle issue</a> for possible workarounds.</p>
<p>Forked processes (including backticks) won't see CGI emulation environment variables. (META: This will hopefully be resolved in the future, it's documented in modperl_env.c:modperl_env_magic_set_all.)</p>
<h1 id="Special-Environment-Variables">Special Environment Variables</h1>
<h2 id="ENV-GATEWAY_INTERFACE"><code>$ENV{GATEWAY_INTERFACE}</code></h2>
<p>The environment variable <code>$ENV{GATEWAY_INTERFACE}</code> is not special in mod_perl 2.0, but the same as any other CGI environment variables, i.e. it'll be enabled only if <code><a>PerlOptions +SetupEnv</a></code> is enabled and its value would be the default:</p>
<pre><code> CGI/1.1</code></pre>
<p>or anything else Apache decides to set it to, but not:</p>
<pre><code> CGI-Perl/1.1</code></pre>
<p>Instead use <code>$ENV{MOD_PERL}</code> (available in both mod_perl generations), which is set to the mod_perl version, like so:</p>
<pre><code> mod_perl/2.000002</code></pre>
<p>Therefore in order to check whether you are running under mod_perl, you'd say:</p>
<pre><code> if ($ENV{MOD_PERL}) { ... }</code></pre>
<p>To check for a specific version it's better to use <code>$ENV{MOD_PERL_API_VERSION}</code></p>
<pre><code> use mod_perl;
use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and
$ENV{MOD_PERL_API_VERSION} >= 2 ); </code></pre>
<h1 id="Apache::-Methods"><code>Apache::</code> Methods</h1>
<h2 id="Apache-request"><code>Apache->request</code></h2>
<p><code>Apache->request</code> has been replaced with <code><a>Apache2::RequestUtil::request()</a></code>.</p>
<p><code><a>Apache2::RequestUtil->request</a></code> usage should be avoided under mod_perl 2.0 <code>$r</code> should be passed around as an argument instead (or in the worst case maintain your own global variable). Since your application may run under threaded mpm, the <code>Apache2::RequestUtil->request</code> usage involves storage and retrieval from the thread local storage, which is expensive.</p>
<p>It's possible to use <code>$r</code> even in CGI scripts running under <code><a>Registry</a></code> modules, without breaking the mod_cgi compatibility. Registry modules convert a script like:</p>
<pre><code> print "Content-type: text/plain";
print "Hello";</code></pre>
<p>into something like:</p>
<pre><code> package Foo;
sub handler {
print "Content-type: text/plain\n\n";
print "Hello";
return Apache2::Const::OK;
}</code></pre>
<p>where the <code>handler()</code> function always receives <code>$r</code> as an argument, so if you change your script to be:</p>
<pre><code> my $r;
$r = shift if $ENV{MOD_PERL};
if ($r) {
$r->content_type('text/plain');
}
else {
print "Content-type: text/plain\n\n";
}
print "Hello"</code></pre>
<p>it'll really be converted into something like:</p>
<pre><code> package Foo;
sub handler {
my $r;
$r = shift if $ENV{MOD_PERL};
if ($r) {
$r->content_type('text/plain');
}
else {
print "Content-type: text/plain\n\n";
}
print "Hello"
return Apache2::Const::OK;
}</code></pre>
<p>The script works under both mod_perl and mod_cgi.</p>
<p>For example CGI.pm 2.93 or higher accepts <code>$r</code> as an argument to its <code>new()</code> function. So does <code>CGI::Cookie::fetch</code> from the same distribution.</p>
<p>Moreover, user's configuration may preclude from <code>Apache2::RequestUtil->request</code> being available at run time. For any location that uses <code>Apache2::RequestUtil->request</code> and uses <code>SetHandler modperl</code>, the configuration should either explicitly enable this feature:</p>
<pre><code> <Location ...>
SetHandler modperl
PerlOptions +GlobalRequest
...
</Location></code></pre>
<p>It's already enabled for <code>SetHandler perl-script</code>:</p>
<pre><code> <Location ...>
SetHandler perl-script
...
</Location></code></pre>
<p>This configuration makes <code>Apache2::RequestUtil->request</code> available <b>only</b> during the response phase (<code><a>PerlResponseHandler</a></code>). Other phases can make <code>Apache2::RequestUtil->request</code> available, by explicitly setting it in the handler that has an access to <code>$r</code>. For example the following skeleton for an <i>authen</i> phase handler makes the <code>Apache2::RequestUtil->request</code> available in the calls made from it:</p>
<pre><code> package MyApache2::Auth;
# PerlAuthenHandler MyApache2::Auth
use Apache2::RequestUtil ();
#...
sub handler {
my $r = shift;
Apache2::RequestUtil->request($r);
# do some calls that rely on Apache2::RequestUtil->request being available
#...
}</code></pre>
<h2 id="Apache-define"><code>Apache->define</code></h2>
<p><code>Apache->define</code> has been replaced with <code><a>Apache2::ServerUtil::exists_config_define()</a></code>.</p>
<h2 id="Apache-can_stack_handlers"><code>Apache->can_stack_handlers</code></h2>
<p><code>Apache->can_stack_handlers</code> is no longer needed, as mod_perl 2.0 can always stack handlers.</p>
<h2 id="Apache-untaint"><code>Apache->untaint</code></h2>
<p><code>Apache->untaint</code> has moved to <code><a>Apache2::ModPerl::Util::untaint()</a></code> and now is a function, rather a class method. It'll will untaint all its arguments. You shouldn't be using this function unless you know what you are doing. Refer to the <i>perlsec</i> manpage for more information.</p>
<p><code><a>Apache2::compat</a></code> provides the backward compatible with mod_perl 1.0 implementation.</p>
<h2 id="Apache-get_handlers"><code>Apache->get_handlers</code></h2>
<p>To get handlers for the server level, mod_perl 2.0 code should use <code><a>Apache2::ServerUtil::get_handlers()</a></code>:</p>
<pre><code> $s->get_handlers(...);</code></pre>
<p>or:</p>
<pre><code> Apache2::ServerUtil->server->get_handlers(...);</code></pre>
<p><code>Apache->get_handlers</code> is avalable via <code><a>Apache2::compat</a></code>.</p>
<p>See also <code><a>Apache2::RequestUtil::get_handlers()</a></code>.</p>
<h2 id="Apache-push_handlers"><code>Apache->push_handlers</code></h2>
<p>To push handlers at the server level, mod_perl 2.0 code should use <code><a>Apache2::ServerUtil::push_handlers()</a></code>:</p>
<pre><code> $s->push_handlers(...);</code></pre>
<p>or:</p>
<pre><code> Apache2::ServerUtil->server->push_handlers(...);</code></pre>
<p><code>Apache->push_handlers</code> is avalable via <code><a>Apache2::compat</a></code>.</p>
<p>See also <code><a>Apache2::RequestUtil::push_handlers()</a></code>.</p>
<h2 id="Apache-set_handlers"><code>Apache->set_handlers</code></h2>
<p>To set handlers at the server level, mod_perl 2.0 code should use <code><a>Apache2::ServerUtil::set_handlers()</a></code>:</p>
<pre><code> $s->set_handlers(...);</code></pre>
<p>or:</p>
<pre><code> Apache2::ServerUtil->server->set_handlers(...);</code></pre>
<p><code>Apache->set_handlers</code> is avalable via <code><a>Apache2::compat</a></code>.</p>
<p>To reset the list of handlers, instead of doing:</p>
<pre><code> $r->set_handlers(PerlAuthenHandler => [ \&OK ]);</code></pre>
<p>do:</p>
<pre><code> $r->set_handlers(PerlAuthenHandler => []);</code></pre>
<p>or</p>
<pre><code> $r->set_handlers(PerlAuthenHandler => undef);</code></pre>
<p>See also <code><a>Apache2::RequestUtil::set_handlers()</a></code>.</p>
<h2 id="Apache-httpd_conf"><code>Apache->httpd_conf</code></h2>
<p><code>Apache->httpd_conf</code> is now <code><a>$s->add_config</a></code>:</p>
<pre><code> require Apache2::ServerUtil;
Apache2::ServerUtil->server->add_config(['require valid-user']);</code></pre>
<p><code>Apache->httpd_conf</code> is avalable via <code><a>Apache2::compat</a></code>.</p>
<p>See also <code><a>Apache2::RequestUtil::add_config()</a></code>.</p>
<h2 id="Apache-unescape_url_info"><code>Apache->unescape_url_info</code></h2>
<p>Apache->unescape_url_info is not available in mod_perl 2.0 API. Use <code>CGI::Util::unescape</code> instead (http://search.cpan.org/dist/CGI.pm/CGI/Util.pm).</p>
<p>It is also available via <code><a>Apache2::compat</a></code> for backwards compatibility.</p>
<h2 id="Apache::exit"><code>Apache::exit()</code></h2>
<p><code>Apache::exit()</code> has been replaced with <code><a>ModPerl::Util::exit()</a></code>.</p>
<h2 id="Apache::gensym"><code>Apache::gensym()</code></h2>
<p>Since Perl 5.6.1 filehandlers are autovivified and there is no need for <code>Apache::gensym()</code> function, since now it can be done with:</p>
<pre><code> open my $fh, "foo" or die $!;</code></pre>
<p>Though the C function <code>modperl_perl_gensym()</code> is available for XS/C extensions writers.</p>
<h2 id="Apache::log_error"><code>Apache::log_error()</code></h2>
<p><code>Apache::log_error()</code> is not available in mod_perl 2.0 API. You can use <code><a>Apache2::Log::log_error()</a></code>:</p>
<pre><code> Apache2::ServerUtil->server->log_error</code></pre>
<p>instead. See the <code><a>Apache2::Log</a></code> manpage.</p>
<h2 id="Apache-warn"><code>Apache->warn</code></h2>
<p><code>$Apache->warn</code> has been removed and exists only in <code><a>Apache2::compat</a></code>. Choose another <code><a>Apache2::Log</a></code> method.</p>
<h2 id="Apache::warn"><code>Apache::warn</code></h2>
<p><code>$Apache::warn</code> has been removed and exists only in <code><a>Apache2::compat</a></code>. Choose another <code><a>Apache2::Log</a></code> method.</p>
<h2 id="Apache::module"><code>Apache::module()</code></h2>
<p><code>Apache::module()</code> has been replaced with the function <code><a>Apache2::Module::loaded()</a></code>, which now accepts a single argument: the module name.</p>
<h1 id="Apache::-Variables"><code>Apache::</code> Variables</h1>
<h2 id="Apache::__T"><code>$Apache::__T</code></h2>
<p><code>$Apache::__T</code> is deprecated in mod_perl 2.0. Use <code>${^TAINT}</code> instead.</p>
<h1 id="Apache::Module::-Methods"><code>Apache::Module::</code> Methods</h1>
<h2 id="Apache::Module-top_module"><code>Apache::Module->top_module</code></h2>
<p><code>Apache::Module->top_module</code> has been replaced with the function <code><a>Apache2::Module::top_module()</a></code>.</p>
<h2 id="Apache::Module-get_config"><code>Apache::Module->get_config</code></h2>
<p><code>Apache::Module->get_config</code> has been replaced with the function <code><a>Apache2::Module::get_config()</a></code>.</p>
<h1 id="Apache::ModuleConfig::-Methods"><code>Apache::ModuleConfig::</code> Methods</h1>
<h2 id="Apache::ModuleConfig-get"><code>Apache::ModuleConfig->get</code></h2>
<p><code>Apache::ModuleConfig->get</code> has been replaced with the function <code><a>Apache2::Module::get_config()</a></code>.</p>
<h1 id="Apache::Server::-Methods-and-Variables"><code>Apache::Server::</code> Methods and Variables</h1>
<h2 id="Apache::Server::CWD"><code>$Apache::Server::CWD</code></h2>
<p><code>$Apache::Server::CWD</code> is deprecated and exists only in <code><a>Apache2::compat</a></code>.</p>
<h2 id="Apache::Server::AddPerlVersion"><code>$Apache::Server::AddPerlVersion</code></h2>
<p><code>$Apache::Server::AddPerlVersion</code> is deprecated and exists only in <code><a>Apache2::compat</a></code>.</p>
<h2 id="Apache::Server::Starting-and-Apache::Server::ReStarting"><code>$Apache::Server::Starting</code> and <code>$Apache::Server::ReStarting</code></h2>
<p><code>$Apache::Server::Starting</code> and <code>$Apache::Server::ReStarting</code> were replaced by <code><a>Apache2::ServerUtil::restart_count()</a></code>. Though both exist in <code><a>Apache2::compat</a></code>.</p>
<h2 id="Apache::Server-warn"><code>Apache::Server->warn</code></h2>
<p><code>Apache::Server->warn</code> has been removed and exists only in <code><a>Apache2::compat</a></code>. Choose another <code><a>Apache2::Log</a></code> method.</p>
<h1 id="Server-Object-Methods">Server Object Methods</h1>
<h2 id="s-register_cleanup"><code>$s->register_cleanup</code></h2>
<p><code>$s->register_cleanup</code> has been replaced with <code><a>APR::Pool::cleanup_register()</a></code> which accepts the pool object as the first argument instead of the server object, a callback function as a second and data variable as the optional third argument. If that data argument was provided it is then passed to the callback function when the time comes for the pool object to get destroyed.</p>
<pre><code> use Apache2::ServerUtil ();
sub cleanup_callback {
my $data = shift;
# your code comes here
return Apache2::Const::OK;
}
$s->pool->cleanup_register(\&cleanup_callback, $data);</code></pre>
<p>See also <code><a>PerlChildExitHandler</a></code>.</p>
<p>In order to register a cleanup handler to be run only once when the main server (not each child process) shuts down, you can register a cleanup handler with <code><a>server_shutdown_cleanup_register()</a></code>.</p>
<h2 id="s-uid"><code>$s->uid</code></h2>
<p>See the next entry.</p>
<h2 id="s-gid"><code>$s->gid</code></h2>
<p>apache-1.3 had server_rec records for server_uid and server_gid. httpd-2.0 doesn't have them, because in httpd-2.0 the directives User and Group are platform specific. And only UNIX supports it: http://httpd.apache.org/docs-2.0/mod/mpm_common.html#user</p>
<p>It's possible to emulate mod_perl 1.0 API doing:</p>
<pre><code> sub Apache2::Server::uid { $< }
sub Apache2::Server::gid { $( }</code></pre>
<p>but the problem is that if the server is started as <i>root</i>, but its child processes are run under a different username, e.g. <i>nobody</i>, at the startup the above function will report the <code>uid</code> and <code>gid</code> values of <i>root</i> and not <i>nobody</i>, i.e. at startup it won't be possible to know what the User and Group settings are in <i>httpd.conf</i>.</p>
<p>META: though we can probably access the parsed config tree and try to fish these values from there. The real problem is that these values won't be available on all platforms and therefore we should probably not support them and let developers figure out how to code around it (e.g. by using <code>$<</code> and <code>$(</code>).</p>
<h1 id="Request-Object-Methods">Request Object Methods</h1>
<h2 id="r-print"><code>$r->print</code></h2>
<pre><code> $r->print($foo);</code></pre>
<p>or</p>
<pre><code> print $foo;</code></pre>
<p>no longer accepts a reference to a scalar as it did in mod_perl 1.0. This optimisation is not needed in the mod_perl 2.0's implementation of <code>print</code>.</p>
<h2 id="r-cgi_env"><code>$r->cgi_env</code></h2>
<p>See the next item</p>
<h2 id="r-cgi_var"><code>$r->cgi_var</code></h2>
<p><code>$r->cgi_env</code> and <code>$r->cgi_var</code> should be replaced with <code><a>$r->subprocess_env</a></code>, which works identically in both mod_perl generations.</p>
<h2 id="r-current_callback"><code>$r->current_callback</code></h2>
<p><code>$r->current_callback</code> is now simply a <code><a>ModPerl::Util::current_callback</a></code> and can be called for any of the phases, including those where <code>$r</code> simply doesn't exist.</p>
<p><code><a>Apache2::compat</a></code> implements <code>$r->current_callback</code> for backwards compatibility.</p>
<h2 id="r-cleanup_for_exec"><code>$r->cleanup_for_exec</code></h2>
<p><code>$r->cleanup_for_exec</code> wasn't a part of the mp1 core API, but lived in a 3rd party module <code>Apache2::SubProcess</code>. That module's functionality is now a part of mod_perl 2.0 API. But Apache 2.0 doesn't need this function any longer.</p>
<p><code><a>Apache2::compat</a></code> implements <code>$r->cleanup_for_exec</code> for backwards compatibility as a NOOP.</p>
<p>See also the <code><a>Apache2::SubProcess</a></code> manpage.</p>
<h2 id="r-get_remote_host"><code>$r->get_remote_host</code></h2>
<p><code><a>get_remote_host()</a></code> is now invoked on the <code><a>connection object</a></code>:</p>
<pre><code> use Apache2::Connection;
$r->connection->get_remote_host();</code></pre>
<p><code>$r->get_remote_host</code> is available through <code><a>Apache2::compat</a></code>.</p>
<h2 id="r-content"><code>$r->content</code></h2>
<p>See the next item.</p>
<h2 id="r-args-in-an-Array-Context"><code>$r->args</code> in an Array Context</h2>
<p><code><a>$r->args</a></code> in 2.0 returns the query string without parsing and splitting it into an array. You can also set the query string by passing a string to this method.</p>
<p><code>$r->content</code> and <code>$r->args</code> in an array context were mistakes that never should have been part of the mod_perl 1.0 API. There are multiple reason for that, among others:</p>
<ul>
<li><p>does not handle multi-value keys</p>
</li>
<li><p>does not handle multi-part content types</p>
</li>
<li><p>does not handle chunked encoding</p>
</li>
<li><p>slurps <code>$r->headers_in->{'content-length'}</code> into a single buffer (bad for performance, memory bloat, possible dos attack, etc.)</p>
</li>
<li><p>in general duplicates functionality (and does so poorly) that is done better in <code>Apache2::Request</code>.</p>
</li>
<li><p>if one wishes to simply read POST data, there is the more modern filter API, along with continued support for <code>read(STDIN, ...)</code> and <code>$r->read($buf, $r->headers_in->{'content-length'}</code>)</p>
</li>
</ul>
<p>You could use <code>CGI.pm</code> or the code in <code><a>Apache2::compat</a></code> (it's slower).</p>
<p>However, now that <code>Apache2::Request</code> has been ported to mod_perl 2.0 you can use it instead and reap the benefits of the fast C implementations of these functions. For documentation on its uses, please see:</p>
<p>http://httpd.apache.org/apreq</p>
<h2 id="r-chdir_file"><code>$r->chdir_file</code></h2>
<p><code>chdir()</code> cannot be used in the threaded environment, therefore <code>$r->chdir_file</code> is not in the mod_perl 2.0 API.</p>
<p>For more information refer to: <a>Threads Coding Issues Under mod_perl</a>.</p>
<h2 id="r-is_main"><code>$r->is_main</code></h2>
<p><code>$r->is_main</code> is not part of the mod_perl 2.0 API. Use <code><a>!$r->main</a></code> instead.</p>
<p>Refer to the <code><a>Apache2::RequestRec</a></code> manpage.</p>
<h2 id="r-filename"><code>$r->filename</code></h2>
<p>When a new <code><a>$r->filename</a></code> is assigned Apache 2.0 doesn't update the finfo structure like it did in Apache 1.3. If the old behavior is desired Apache2::compat's <a>overriding</a> can be used. Otherwise one should explicitly update the finfo struct when desired as explained in the <code><a>filename</a></code> API entry.</p>
<h2 id="r-finfo"><code>$r->finfo</code></h2>
<p>As Apache 2.0 doesn't provide an access to the stat structure, but hides it in the opaque object <code>$r->finfo</code> now returns an <code><a>APR::Finfo</a></code> object. You can then invoke the <code><a>APR::Finfo</a></code> accessor methods on it.</p>
<p>It's also possible to adjust the mod_perl 1.0 code using Apache2::compat's <a>overriding</a>. For example:</p>
<pre><code> use Apache2::compat;
Apache2::compat::override_mp2_api('Apache2::RequestRec::finfo');
my $is_writable = -w $r->finfo;
Apache2::compat::restore_mp2_api('Apache2::RequestRec::finfo');</code></pre>
<p>which internally does just the following:</p>
<pre><code> stat $r->filename and return \*_;</code></pre>
<p>So may be it's easier to just change the code to use this directly, so the above example can be adjusted to be:</p>
<pre><code> my $is_writable = -w $r->filename;</code></pre>
<p>with the performance penalty of an extra <code>stat()</code> system call. If you don't want this extra call, you'd have to write:</p>
<pre><code> use APR::Finfo;
use Apache2::RequestRec;
use APR::Const -compile => qw(WWRITE);
my $is_writable = $r->finfo->protection & APR::WWRITE,</code></pre>
<p>See the <code><a>APR::Finfo</a></code> manpage for more information.</p>
<h2 id="r-notes"><code>$r->notes</code></h2>
<p>Similar to <code><a>headers_in()</a></code>, <code><a>headers_out()</a></code> and <code><a>err_headers_out()</a></code> in mod_perl 2.0, <code><a>$r->notes()</a></code> returns an <code><a>APR::Table</a></code> object, which can be used as a tied hash or calling its <i><a>get()</a></i> / <i><a>set()</a></i> / <i><a>add()</a></i> / <i><a>unset()</a></i> methods.</p>
<p>It's also possible to adjust the mod_perl 1.0 code using <code><a>Apache2::compat</a></code>'s <a>overriding</a>:</p>
<pre><code> use Apache2::compat;
Apache2::compat::override_mp2_api('Apache2::RequestRec::notes');
$r->notes($key => $val);
$val = $r->notes($key);
Apache2::compat::restore_mp2_api('Apache2::RequestRec::notes');</code></pre>
<p>See the <code><a>Apache2::RequestRec</a></code> manpage.</p>
<h2 id="r-header_in"><code>$r->header_in</code></h2>
<p>See <code><a href="#C__r_E_gt_err_header_out_">$r->err_header_out</a></code>.</p>
<h2 id="r-header_out"><code>$r->header_out</code></h2>
<p>See <code><a href="#C__r_E_gt_err_header_out_">$r->err_header_out</a></code>.</p>
<h2 id="r-err_header_out"><code>$r->err_header_out</code></h2>
<p><code>header_in()</code>, <code>header_out()</code> and <code>err_header_out()</code> are not available in 2.0. Use <code><a>headers_in()</a></code>, <code><a>headers_out()</a></code> and <code><a>err_headers_out()</a></code> instead (which should be used in 1.0 as well). For example you need to replace:</p>
<pre><code> $r->err_header_out("Pragma" => "no-cache");</code></pre>
<p>with:</p>
<pre><code> $r->err_headers_out->{'Pragma'} = "no-cache";</code></pre>
<p>See the <a>Apache2::RequestRec</a> manpage.</p>
<h2 id="r-register_cleanup"><code>$r->register_cleanup</code></h2>
<p>Similarly to <code>$s->register_cleanup</code>, <code>$r->register_cleanup</code> has been replaced with <code><a>APR::Pool::cleanup_register()</a></code> which accepts the pool object as the first argument instead of the request object. e.g.:</p>
<pre><code> sub cleanup_callback { my $data = shift; ... }
$r->pool->cleanup_register(\&cleanup_callback, $data);</code></pre>
<p>where the last argument <code>$data</code> is optional, and if supplied will be passed as the first argument to the callback function.</p>
<p>See the <code><a>APR::Pool</a></code> manpage.</p>
<h2 id="r-post_connection"><code>$r->post_connection</code></h2>
<p><code>$r->post_connection</code> has been replaced with:</p>
<pre><code> $r->connection->pool->cleanup_register();</code></pre>
<p>See the <code><a>APR::Pool</a></code> manpage.</p>
<h2 id="r-request"><code>$r->request</code></h2>
<p>Use <code><a>Apache2::RequestUtil->request</a></code>.</p>
<h2 id="r-send_fd"><code>$r->send_fd</code></h2>
<p>mod_perl 2.0 provides a new method <code><a>sendfile()</a></code> instead of <code>send_fd</code>, so if your code used to do:</p>
<pre><code> open my $fh, "<$file" or die "$!";
$r->send_fd($fh);
close $fh;</code></pre>
<p>now all you need is:</p>
<pre><code> $r->sendfile($file);</code></pre>
<p>There is also a compatibility implementation of send_fd in pure perl in <code><a>Apache2::compat</a></code>.</p>
<p>XXX: later we may provide a direct access to the real send_fd. That will be possible if we figure out how to portably convert PerlIO/FILE into apr_file_t (with help of apr_os_file_put, which expects a native filehandle, so I'm not sure whether this will work on win32).</p>
<h2 id="r-send_http_header"><code>$r->send_http_header</code></h2>
<p>This method is not needed in 2.0, though available in <code><a>Apache2::compat</a></code>. 2.0 handlers only need to set the <i>Content-type</i> via <code><a>$r->content_type($type)</a></code>.</p>
<h2 id="r-server_root_relative"><code>$r->server_root_relative</code></h2>
<p>This method was replaced with <code><a>Apache2::ServerUtil::server_root_relative()</a></code> function and its first argument is a <i>pool</i> object. For example:</p>
<pre><code> # during request
$conf_dir = Apache2::server_root_relative($r->pool, 'conf');
# during startup
$conf_dir = Apache2::server_root_relative($s->pool, 'conf');</code></pre>
<p>Note that the old form</p>
<pre><code> my $conf_dir = Apache->server_root_relative('conf');</code></pre>
<p>is no longer valid - <code>server_root_relative()</code> must be explicitly passed a pool.</p>
<p>The old functionality is available with <code><a>Apache2::compat</a></code>.</p>
<h2 id="r-hard_timeout"><code>$r->hard_timeout</code></h2>
<p>See <code><a href="#C__r_E_gt_kill_timeout_">$r->kill_timeout</a></code>.</p>
<h2 id="r-reset_timeout"><code>$r->reset_timeout</code></h2>
<p>See <code><a href="#C__r_E_gt_kill_timeout_">$r->kill_timeout</a></code>.</p>
<h2 id="r-soft_timeout"><code>$r->soft_timeout</code></h2>
<p>See <code><a href="#C__r_E_gt_kill_timeout_">$r->kill_timeout</a></code>.</p>
<h2 id="r-kill_timeout"><code>$r->kill_timeout</code></h2>
<p>The functions <code>$r->hard_timeout</code>, <code>$r->reset_timeout</code>, <code>$r->soft_timeout</code> and <code>$r->kill_timeout</code> aren't needed in mod_perl 2.0. <code><a>Apache2::compat</a></code> implements these functions for backwards compatibility as NOOPs.</p>
<h2 id="r-set_byterange"><code>$r->set_byterange</code></h2>
<p>See <code><a href="#C__r_E_gt_each_byterange_">$r->each_byterange</a></code>.</p>
<h2 id="r-each_byterange"><code>$r->each_byterange</code></h2>
<p>The functions <code>$r->set_byterange</code> and <code>$r->each_byterange</code> aren't in the Apache 2.0 API, and therefore don't exist in mod_perl 2.0. The byterange serving functionality is now implemented in the ap_byterange_filter, which is a part of the core http module, meaning that it's automatically taking care of serving the requested ranges off the normal complete response. There is no need to configure it. It's executed only if the appropriate request headers are set. These headers aren't listed here, since there are several combinations of them, including the older ones which are still supported. For a complete info on these see <i>modules/http/http_protocol.c</i>.</p>
<h1 id="Apache::Connection"><code>Apache::Connection</code></h1>
<h2 id="connection-auth_type"><code>$connection->auth_type</code></h2>
<p>The record <i>auth_type</i> doesn't exist in the Apache 2.0's connection struct. It exists only in the request record struct. The new accessor in 2.0 API is <code><a>$r->ap_auth_type</a></code>.</p>
<p><code><a>Apache2::compat</a></code> provides a back compatibility method, though it relies on the availability of the global <code>Apache->request</code>, which requires the configuration to have:</p>
<pre><code> PerlOptions +GlobalRequest</code></pre>
<p>to set it up for earlier stages than response handler.</p>
<h2 id="connection-user"><code>$connection->user</code></h2>
<p>This method is deprecated in mod_perl 1.0 and <code><a>$r->user</a></code> should be used instead for both mod_perl generations. <code>$r->user()</code> method is available since mod_perl version 1.24_01.</p>
<h2 id="connection-local_addr"><code>$connection->local_addr</code></h2>
<p>See <code><a href="#C__connection_E_gt_remote_addr_">$connection->remote_addr</a></code></p>
<h2 id="connection-remote_addr"><code>$connection->remote_addr</code></h2>
<p><code><a>$c->local_addr</a></code> and <code><a>$c->remote_addr</a></code> return an <code><a>APR::SockAddr</a></code> object and you can use this object's methods to retrieve the wanted bits of information, so if you had a code like:</p>
<pre><code> use Socket 'sockaddr_in';
my $c = $r->connection;
my ($serverport, $serverip) = sockaddr_in($c->local_addr);
my ($remoteport, $remoteip) = sockaddr_in($c->remote_addr);</code></pre>
<p>now it'll be written as:</p>
<pre><code> require APR::SockAddr;
my $c = $r->connection;
my $serverport = $c->local_addr->port;
my $serverip = $c->local_addr->ip_get;
my $remoteport = $c->remote_addr->port;
my $remoteip = $c->remote_addr->ip_get;</code></pre>
<p>It's also possible to adjust the code using Apache2::compat's <a>overriding</a>:</p>
<pre><code> use Socket 'sockaddr_in';
use Apache2::compat;
Apache2::compat::override_mp2_api('Apache2::Connection::local_addr');
my ($serverport, $serverip) = sockaddr_in($r->connection->local_addr);
Apache2::compat::restore_mp2_api('Apache2::Connection::local_addr');
Apache2::compat::override_mp2_api('Apache::Connection::remote_addr');
my ($remoteport, $remoteip) = sockaddr_in($r->connection->remote_addr);
Apache2::compat::restore_mp2_api('Apache::Connection::remote_addr');</code></pre>
<h1 id="Apache::File"><code>Apache::File</code></h1>
<p>The methods from mod_perl 1.0's module <code>Apache::File</code> have been either moved to other packages or removed.</p>
<h2 id="new-open-and-close"><code>new()</code>, <code>open()</code> and <code>close()</code></h2>
<p>The methods <code>new()</code>, <code>open()</code> and <code>close()</code> were removed. See the back compatibility implementation in the module <code><a>Apache2::compat</a></code>.</p>
<p>Because of that some of the idioms have changes too. If previously you were writing:</p>
<pre><code> my $fh = Apache::File->new($r->filename)
or return Apache::DECLINED;
# Slurp the file (hopefully it's not too big).
my $content = do { local $/; <$fh> };
close $fh;</code></pre>
<p>Now, you would write that using <code><a>Apache2::RequestUtil::slurp_filename()</a></code>:</p>
<pre><code> use Apache2::RequestUtil ();
my $content = ${ $r->slurp_filename() };</code></pre>
<h2 id="tmpfile"><code>tmpfile()</code></h2>
<p>The method <code>tmpfile()</code> was removed since Apache 2.0 doesn't have the API for this method anymore.</p>
<p>See <code>File::Temp</code>, or the back compatibility implementation in the module <code><a>Apache2::compat</a></code>.</p>
<p>With Perl v5.8.0 you can create anonymous temporary files:</p>
<pre><code> open $fh, "+>", undef or die $!;</code></pre>
<p>That is a literal <code>undef</code>, not an undefined value.</p>
<h1 id="Apache::Util"><code>Apache::Util</code></h1>
<p>A few <code><a>Apache2::Util</a></code> functions have changed their interface.</p>
<h2 id="Apache::Util::size_string"><code>Apache::Util::size_string()</code></h2>
<p><code>Apache::Util::size_string()</code> has been replaced with <code><a>APR::String::format_size()</a></code>, which returns formatted strings of only 4 characters long.</p>
<h2 id="Apache::Util::escape_uri"><code>Apache::Util::escape_uri()</code></h2>
<p><code>Apache::Util::escape_uri()</code> has been replaced with <code><a>Apache2::Util::escape_path()</a></code> and requires a pool object as a second argument. For example:</p>
<pre><code> $escaped_path = Apache2::Util::escape_path($path, $r->pool);</code></pre>
<h2 id="Apache::Util::unescape_uri"><code>Apache::Util::unescape_uri()</code></h2>
<p><code>Apache::Util::unescape_uri()</code> has been replaced with <code><a>Apache2::URI::unescape_url()</a></code>.</p>
<h2 id="Apache::Util::escape_html"><code>Apache::Util::escape_html()</code></h2>
<p><code>Apache::Util::escape_html</code> is not available in mod_perl 2.0. Use <code>HTML::Entities</code> instead (http://search.cpan.org/dist/HTML-Parser/lib/HTML/Entities.pm).</p>
<p>It's also available via <code><a>Apache2::compat</a></code> for backwards compatibility.</p>
<h2 id="Apache::Util::parsedate"><code>Apache::Util::parsedate()</code></h2>
<p><code>Apache::Util::parsedate()</code> has been replaced with <code><a>APR::Date::parse_http()</a></code>.</p>
<h2 id="Apache::Util::ht_time"><code>Apache::Util::ht_time()</code></h2>
<p><code><a>Apache2::Util::ht_time()</a></code> now requires a <code><a>pool</a></code> object as a first argument.</p>
<p>For example:</p>
<pre><code> use Apache2::Util ();
$fmt = '%a, %d %b %Y %H:%M:%S %Z';
$gmt = 1;
$fmt_time = Apache2::Util::ht_time($r->pool, time(), $fmt, $gmt);</code></pre>
<p>See the <a>Apache2::Util</a> manpage.</p>
<p>It's also possible to adjust the mod_perl 1.0 code using Apache2::compat's <a>overriding</a>.</p>
<p>For example:</p>
<pre><code> use Apache2::compat;
Apache2::compat::override_mp2_api('Apache2::Util::ht_time');
$fmt_time = Apache2::Util::ht_time(time(), $fmt, $gmt);
Apache2::compat::restore_mp2_api('Apache2::Util::ht_time');</code></pre>
<h2 id="Apache::Util::validate_password"><code>Apache::Util::validate_password()</code></h2>
<p><code>Apache::Util::validate_password()</code> has been replaced with <code><a>APR::Util::password_validate()</a></code>. For example:</p>
<pre><code> my $ok = Apache2::Util::password_validate("stas", "ZeO.RAc3iYvpA");</code></pre>
<h1 id="Apache::URI"><code>Apache::URI</code></h1>
<h2 id="Apache::URI-parse-r-uri"><code>Apache::URI->parse($r, [$uri])</code></h2>
<p><code>parse()</code> and its associated methods have moved into the <code><a>APR::URI</a></code> package. For example:</p>
<pre><code> my $curl = $r->construct_url;
APR::URI->parse($r->pool, $curl);</code></pre>
<p>See the <code><a>APR::URI</a></code> manpage.</p>
<h2 id="unparse"><code>unparse()</code></h2>
<p>Other than moving to the package <code><a>APR::URI</a></code>, <code><a>unparse</a></code> is now protocol-agnostic. Apache won't use <i>http</i> as the default protocol if <i>hostname</i> was set, but <i>scheme</i> wasn't not. So the following code:</p>
<pre><code> # request http://localhost.localdomain:8529/TestAPI::uri
my $parsed = $r->parsed_uri;
$parsed->hostname($r->get_server_name);
$parsed->port($r->get_server_port);
print $parsed->unparse;</code></pre>
<p>prints:</p>
<pre><code> //localhost.localdomain:8529/TestAPI::uri</code></pre>
<p>forcing you to make sure that the scheme is explicitly set. This will do the right thing:</p>
<pre><code> # request http://localhost.localdomain:8529/TestAPI::uri
my $parsed = $r->parsed_uri;
$parsed->hostname($r->get_server_name);
$parsed->port($r->get_server_port);
$parsed->scheme('http');
print $parsed->unparse;</code></pre>
<p>prints:</p>
<pre><code> http://localhost.localdomain:8529/TestAPI::uri</code></pre>
<p>See the <code><a>APR::URI</a></code> manpage for more information.</p>
<p>It's also possible to adjust the behavior to be mod_perl 1.0 compatible using Apache2::compat's <a>overriding</a>, in which case <code>unparse()</code> will transparently set <i>scheme</i> to <i>http</i>.</p>
<pre><code> # request http://localhost.localdomain:8529/TestAPI::uri
Apache2::compat::override_mp2_api('APR::URI::unparse');
my $parsed = $r->parsed_uri;
# set hostname, but not the scheme
$parsed->hostname($r->get_server_name);
$parsed->port($r->get_server_port);
print $parsed->unparse;
Apache2::compat::restore_mp2_api('APR::URI::unparse');</code></pre>
<p>prints:</p>
<pre><code> http://localhost.localdomain:8529/TestAPI::uri</code></pre>
<h1 id="Miscellaneous">Miscellaneous</h1>
<h2 id="Method-Handlers">Method Handlers</h2>
<p>In mod_perl 1.0 the method handlers could be specified by using the <code>($$)</code> prototype:</p>
<pre><code> package Bird;
@ISA = qw(Eagle);
sub handler ($$) {
my ($class, $r) = @_;
...;
}</code></pre>
<p>mod_perl 2.0 doesn't handle callbacks with <code>($$)</code> prototypes differently than other callbacks (as it did in mod_perl 1.0), mainly because several callbacks in 2.0 have more arguments than just <code>$r</code>, so the <code>($$)</code> prototype doesn't make sense anymore. Therefore if you want your code to work with both mod_perl generations and you can allow the luxury of:</p>
<pre><code> require 5.6.0;</code></pre>
<p>or if you need the code to run only on mod_perl 2.0, use the <i>method</i> subroutine attribute. (The subroutine attributes are supported in Perl since version 5.6.0.)</p>
<p>Here is the same example rewritten using the <i>method</i> subroutine attribute:</p>
<pre><code> package Bird;
@ISA = qw(Eagle);
sub handler : method {
my ($class, $r) = @_;
...;
}</code></pre>
<p>See the <i>attributes</i> manpage.</p>
<p>If <code>Class->method</code> syntax is used for a <code>Perl*Handler</code>, the <code>:method</code> attribute is not required.</p>
<p>The porting tutorial provides <a>examples</a> on how to use the same code base under both mod_perl generations when the handler has to be a method.</p>
<h2 id="Stacked-Handlers">Stacked Handlers</h2>
<p>Both mod_perl 1.0 and 2.0 support the ability to register more than one handler in each runtime phase, a feature known as stacked handlers. For example,</p>
<pre><code> PerlAuthenHandler My::First My::Second</code></pre>
<p>The behavior of stacked Perl handlers differs between mod_perl 1.0 and 2.0. In 2.0, mod_perl respects the run-type of the underlying hook - it does not run all configured Perl handlers for each phase but instead behaves in the same way as Apache does when multiple handlers are configured, respecting (or ignoring) the return value of each handler as it is called.</p>
<p>See <a>Stacked Handlers</a> for a complete description of each hook and its run-type.</p>
<h1 id="Apache::src"><code>Apache::src</code></h1>
<p>For those who write 3rd party modules using XS, this module was used to supply mod_perl specific include paths, defines and other things, needed for building the extensions. mod_perl 2.0 makes things transparent with <code><a>ModPerl::MM</a></code>.</p>
<p>Here is how to write a simple <i>Makefile.PL</i> for modules wanting to build XS code against mod_perl 2.0:</p>
<pre><code> use mod_perl 2.0;
use ModPerl::MM ();
ModPerl::MM::WriteMakefile(
NAME => "Foo",
);</code></pre>
<p>and everything will be done for you.</p>
<p>META: we probably will have a compat layer at some point.</p>
<p>META: move this section to the devel/porting and link there instead</p>
<h1 id="Apache::Table"><code>Apache::Table</code></h1>
<p><code>Apache::Table</code> has been renamed to <code><a>APR::Table</a></code>.</p>
<h1 id="Apache::SIG"><code>Apache::SIG</code></h1>
<p><code>Apache::SIG</code> currently exists only <code><a>Apache2::compat</a></code> and it does nothing.</p>
<h1 id="Apache::StatINC"><code>Apache::StatINC</code></h1>
<p><code>Apache::StatINC</code> has been replaced by <code><a>Apache2::Reload</a></code>, which works for both mod_perl generations. To migrate to <code>Apache2::Reload</code> simply replace:</p>
<pre><code> PerlInitHandler Apache::StatINC</code></pre>
<p>with:</p>
<pre><code> PerlInitHandler Apache2::Reload</code></pre>
<p>However <code>Apache2::Reload</code> provides an extra functionality, covered in the module's manpage.</p>
<h1 id="Maintainers">Maintainers</h1>
<p>Maintainer is the person(s) you should contact with updates, corrections and patches.</p>
<ul>
<li><p>Stas Bekman [http://stason.org/]</p>
</li>
</ul>
<h1 id="Authors">Authors</h1>
<ul>
<li><p>Stas Bekman [http://stason.org/]</p>
</li>
</ul>
<p>Only the major authors are listed above. For contributors see the Changes file.</p>
<h1 id="POD-ERRORS">POD ERRORS</h1>
<p>Hey! <b>The above document had some coding errors, which are explained below:</b></p>
<dl>
<dt id="Around-line-80">Around line 80:</dt>
<dd>
<p>alternative text 'PerlOptions +/-ParseHeaders' contains non-escaped | or /</p>
</dd>
<dt id="Around-line-92">Around line 92:</dt>
<dd>
<p>alternative text 'PerlOptions +/-SetupEnv' contains non-escaped | or /</p>
</dd>
<dt id="Around-line-170">Around line 170:</dt>
<dd>
<p>An empty L<></p>
</dd>
</dl>
</body>
</html>
|