File: custom.pod

package info (click to toggle)
libapache2-mod-perl2 2.0.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 12,016 kB
  • sloc: perl: 97,771; ansic: 14,493; makefile: 51; sh: 18
file content (1412 lines) | stat: -rw-r--r-- 46,416 bytes parent folder | download | duplicates (10)
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
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
=head1 NAME

Apache Server Configuration Customization in Perl

=head1 Description

This chapter explains how to create custom Apache configuration
directives in Perl.

=head1 Incentives

mod_perl provides several ways to pass custom configuration
information to the modules.

The simplest way to pass custom information from the configuration
file to the Perl module is to use the
C<L<PerlSetVar|docs::2.0::user::config::config/C_PerlSetVar_>> and
C<L<PerlAddVar|docs::2.0::user::config::config/C_PerlAddVar_>>
directives. For example:

  PerlSetVar Secret "Matrix is us"

and in the mod_perl code this value can be retrieved as:

  my $secret = $r->dir_config("Secret");

Another alternative is to add custom configuration directives. There
are several reasons for choosing this approach:

=over

=item *

When the expected value is not a simple argument, but must be supplied
using a certain syntax, Apache can verify at startup time that this
syntax is valid and abort the server start up if the syntax is
invalid.

=item *

Custom configuration directives are faster because their values are
parsed at the startup time, whereas C<PerlSetVar> and C<PerlAddVar>
values are parsed at the request time.

=item *

It's possible that some other modules have accidentally chosen to use
the same key names but for absolutely different needs. So the two now
can't be used together. Of course this collision can be avoided if a
unique to your module prefix is used in the key names. For example:

    PerlSetVar ApacheFooSecret "Matrix is us"

=back

Finally, modules can be configured in pure Perl using
C<L<E<lt>PerlE<gt>
Sections|docs::2.0::user::config::config/C_E_lt_PerlE_gt___Sections>>
or L<a startup
file|docs::2.0::user::handlers::server/Startup_File>, by simply
modifying the global variables in the module's package. This approach
could be undesirable because it requires a use of globals, which we
all try to reduce. A bigger problem with this approach is that you
can't have different settings for different sections of the site
(since there is only one version of a global variable), something that
the previous two approaches easily achieve.

=head1 Creating and Using Custom Configuration Directives

In mod_perl 2.0, adding new configuration directives is a piece of
cake, because it requires no XS code and I<Makefile.PL>, needed in
case of mod_perl 1.0. In mod_perl 2.0, custom directives are
implemented in pure Perl.

Here is a very basic module that declares two new configuration
directives: C<MyParameter>, which accepts one or more arguments, and
C<MyOtherParameter> which accepts a single argument. C<MyParameter>
validates that its arguments are valid strings.

  #file:MyApache2/MyParameters.pm
  #-----------------------------
  package MyApache2::MyParameters;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache2::Const -compile => qw(OR_ALL ITERATE);
  
  use Apache2::CmdParms ();
  use Apache2::Module ();
  use Apache2::Directive ();
  
  my @directives = (
      {
       name         => 'MyParameter',
       func         => __PACKAGE__ . '::MyParameter',
       req_override => Apache2::Const::OR_ALL,
       args_how     => Apache2::Const::ITERATE,
       errmsg       => 'MyParameter Entry1 [Entry2 ... [EntryN]]',
      },
      {
       name         => 'MyOtherParameter',
      },
  );
  Apache2::Module::add(__PACKAGE__, \@directives);
  
  sub MyParameter {
      my ($self, $parms, @args) = @_;
      $self->{MyParameter} = \@args;
  
      # validate that the arguments are strings
      for (@args) {
          unless (/^\w+$/) {
              my $directive = $parms->directive;
              die sprintf "error: MyParameter at %s:%d expects " .
                  "string arguments: ('$_' is not a string)\n",
                  $directive->filename, $directive->line_num;
          }
      }
  }
  1;

And here is how to use it in I<httpd.conf>:

  # first load the module so Apache will recognize the new directives
  PerlLoadModule MyApache2::MyParameters
  
  MyParameter one two three
  MyOtherParameter Foo
  <Location /perl>
    MyParameter eleven twenty
    MyOtherParameter Bar
  </Location>

The following sections discuss this and more advanced modules in
detail.

A minimal configuration module is comprised of three groups of elements:

=over

=item * An array C<L<@directives|/C__CMDS_>> for declaring the new
directives and their behavior.

=item * A call to
C<L<Apache2::Module::add()|docs::2.0::api::Apache2::Module/C_add_>> to
register the new directives with apache.

=item * A subroutine per each new directive, which is called when the
directive is seen

=back



=head2 C<@directives>

C<@directives> is an array of hash references. Each
hash represents a separate new configuration directive. In our example
we had:

  my @directives = (
      {
       name         => 'MyParameter',
       func         => __PACKAGE__ . '::MyParameter',
       req_override => Apache2::Const::OR_ALL,
       args_how     => Apache2::Const::ITERATE,
       errmsg       => 'MyParameter Entry1 [Entry2 ... [EntryN]]',
      },
      {
       name         => 'MyOtherParameter',
      },
  );

This structure declares two new directives: C<MyParameter> and
C<MyOtherParameter>. You have to declare at least the name of the new
directive, which is how we have declared the C<MyOtherParameter>
directive. mod_perl will fill in the rest of the configuration using
the defaults described next.

These are the attributes that can be used to define the directives
behavior: I<L<name|/C_name_>>, I<L<func|/C_func_>>,
I<L<args_how|/C_args_how_>>, I<L<req_override|/C_req_override_>> and
I<L<errmsg|/C_errmsg_>>. They are discussed in the following sections.

It is worth noting that in previous versions of mod_perl, it was
necessary to call this variable @APACHE_MODULE_COMMANDS. It is not
the case anymore, and we consistently use the name @directives in 
the documentation for clarity. It can be named anything at all.

=head3 C<name>

This is the only required attribute. And it declares the name of the
new directive as it'll be used in I<httpd.conf>.

=head3 C<func>

The I<func> attribute expects a reference to a function or a function
name. This function is called by httpd every time it encounters the
directive that is described by this entry while parsing the
configuration file. Therefore it's invoked once for every instance of
the directive at the server startup, and once per request per instance
in the I<.htaccess> file.

This function accepts two or more arguments, L<depending on the
I<args_how> attribute's value|/Directive_Syntax_Definition_Constants>.

This attribute is optional. If not supplied, mod_perl will try to use
a function in the current package whose name is the same as of the
directive in question. In our example with C<MyOtherParameter>,
mod_perl will use:

  __PACKAGE__ . '::MyOtherParameter'

as a name of a subroutine and it anticipates that it exists in that
package.

=head3 C<req_override>

The I<> attribute defines the valid scope in which this directive can
appear. There are L<several
constants|/Directive_Scope_Definition_Constants> which map onto the
corresponding Apache macros. These constants should be imported from
the C<L<Apache2::Const|docs::2.0::api::Apache2::Const>>
package.

For example, to use the C<OR_ALL> constant, which allows directives to
be defined anywhere, first, it needs to be imported:

  use Apache2::Const -compile => qw(OR_ALL);

and then assigned to the I<req_override> attribute:

  req_override => Apache2::Const::OR_ALL,

It's possible to combine several options using the unary
operators. For example, the following setting:

  req_override => Apache2::Const::RSRC_CONF | Apache2::Const::ACCESS_CONF

will allow the directive to appear anywhere in I<httpd.conf>, but
forbid it from ever being used in I<.htaccess> files:

This attribute is optional. If not supplied, the default value of
C<L<Apache2::Const::OR_ALL|/C_Apache2__OR_ALL_>> is used.

=head3 C<args_how>

Directives can receive zero, one or many arguments. In order to help
Apache validate that the number of arguments is valid, the I<args_how>
attribute should be set to the desired value. Similar to the
I<L<req_override|/C_req_override_>> attribute, the
C<L<Apache2::Const|docs::2.0::api::Apache2::Const>> package provides a
special C<L<:cmd_how|docs::2.0::api::Apache2::Const/C__cmd_how_>>
constants group which maps to the corresponding Apache macros.  There
are L<several
constants|/Directive_Syntax_Definition_Constants> to choose from.

In our example, the directive C<MyParameter> accepts one or more
arguments, therefore we have the
C<L<Apache2::Const::ITERATE|/C_Apache2__ITERATE_>> constant:

       args_how => Apache2::Const::ITERATE,

This attribute is optional. If not supplied, the default value of
C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>> is used.


=head3 C<errmsg>

The I<errmsg> attribute provides a short but succinct usage statement
that summarizes the arguments that the directive takes. It's used by
Apache to generate a descriptive error message, when the directive is
configured with a wrong number of arguments.

In our example, the directive C<MyParameter> accepts one or more
arguments, therefore we have chosen the following usage string:

       errmsg => 'MyParameter Entry1 [Entry2 ... [EntryN]]',

This attribute is optional. If not supplied, the default value of will
be a string based on the directive's I<L<name|/C_name_>> and
I<L<args_how|/C_args_how_>> attributes.

=head3 C<cmd_data>

Sometimes it is useful to pass information back to the directive
handler callback.  For instance, if you use the I<func> parameter
to specify the same callback for two different directives you 
might want to know which directive is being called currently.
To do this, you can use the I<cmd_data> parameter, which allows
you to store arbitrary strings for later retrieval from your
directive handler.  For instance:

  my @directives = (
      {
       name         => '<Location',
       # func defaults to Location()
       req_override => Apache2::Const::RSRC_CONF,
       args_how     => Apache2::Const::RAW_ARGS,
      },
      {
       name         => '<LocationMatch',
       func         => Location,
       req_override => Apache2::Const::RSRC_CONF,
       args_how     => Apache2::Const::RAW_ARGS,
       cmd_data     => '1',
      },
  );

Here, we are using the C<Location()> function to process both
the C<Location> and C<LocationMatch> directives.  In the
C<Location()> callback we can check the data in the I<cmd_data> slot
to see whether the directive being processed is C<LocationMatch>
and alter our logic accordingly.  How? Through the 
C<info()> method exposed by the C<Apache2::CmdParms> class.

  use Apache2::CmdParms ();
  
  sub Location {
  
    my ($cfg, $parms, $data) = @_;
  
    # see if we were called via LocationMatch
    my $regex = $parms->info;
  
    # continue along
  }

In case you are wondering, C<Location> and C<LocationMatch> were
chosen for a reason - this is exactly how httpd core handles these
two directives.

=head2 Registering the new directives

Once the C<L<@directives|/C__CMDS_>> array is populated, it needs to be
registered with apache using 
C<L<Apache2::Module::add()|docs::2.0::api::Apache2::Module/C_add_>>

  Apache2::Module::add(__PACKAGE__, \@directives);

=head2 Directive Scope Definition Constants

The I<L<req_override|/C_req_override_>> attribute specifies the
configuration scope in which it's valid to use a given configuration
directive. This attribute's value can be any of or a combination of
the following constants:

(these constants are declared in I<httpd-2.0/include/http_config.h>.)

=head3 C<Apache2::Const::OR_NONE>

The directive cannot be overridden by any of the C<AllowOverride>
options.

=head3 C<Apache2::Const::OR_LIMIT>

The directive can appear within directory sections, but not outside
them.  It is also allowed within I<.htaccess> files, provided that
C<AllowOverride Limit> is set for the current directory.

=head3 C<Apache2::Const::OR_OPTIONS>

The directive can appear anywhere within I<httpd.conf>, as well as
within I<.htaccess> files provided that C<AllowOverride Options> is
set for the current directory.

=head3 C<Apache2::Const::OR_FILEINFO>

The directive can appear anywhere within I<httpd.conf>, as well as
within I<.htaccess> files provided that C<AllowOverride FileInfo> is
set for the current directory.

=head3 C<Apache2::Const::OR_AUTHCFG>

The directive can appear within directory sections, but not outside
them.  It is also allowed within I<.htaccess> files, provided that
C<AllowOverride AuthConfig> is set for the current directory.

=head3 C<Apache2::Const::OR_INDEXES>

The directive can appear anywhere within I<httpd.conf>, as well as
within I<.htaccess> files provided that C<AllowOverride Indexes> is
set for the current directory.

=head3 C<Apache2::Const::OR_UNSET>

META: details? "unset a directive (in Allow)"

=head3 C<Apache2::Const::ACCESS_CONF>

The directive can appear within directory sections.  The directive is
not allowed in I<.htaccess> files.

=head3 C<Apache2::Const::RSRC_CONF>

The directive can appear in I<httpd.conf> outside a directory section
(C<E<lt>DirectoryE<gt>>, C<E<lt>LocationE<gt>> or C<E<lt>FilesE<gt>>;
also C<E<lt>FilesMatchE<gt>> and kin).  The directive is not allowed
in I<.htaccess> files.

=head3 C<Apache2::Const::EXEC_ON_READ>

Force directive to execute a command which would modify the
configuration (like including another file, or C<IFModule>).

Normally, Apache first parses the configuration tree and then executes
the directives it has encountered (e.g., C<SetEnv>). But there are
directives that must be executed during the initial parsing, either
because they affect the configuration tree (e.g., C<Include> may load
extra configuration) or because they tell Apache about new directives
(e.g., C<IfModule> or C<PerlLoadModule>, may load a module, which
installs handlers for new directives). These directives must have the
C<Apache2::Const::EXEC_ON_READ> turned on.

=head3 C<Apache2::Const::OR_ALL>

The directive can appear anywhere.  It is not limited in any way.




=head2 Directive Callback Subroutine

Depending on the value of the I<L<args_how|/C_args_how_>> attribute
the callback subroutine, specified with the I<L<func|/C_func_>>
attribute, will be called with two or more arguments. The first two
arguments are always C<$self> and C<$parms>. A typical callback
function which expects a single value
(C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>>) might look like the following:

  sub MyParam {
      my ($self, $parms, $arg) = @_;
      $self->{MyParam} = $arg;
  }

In this function we store the passed single value in the configuration
object, using the directive's name (assuming that it was C<MyParam>)
as the key.

Let's look at the subroutine arguments in detail:

=over

=item 1

C<$self> is the current container's configuration object.

This configuration object is a reference to a hash, in which you can
store arbitrary key/value pairs. When the directive callback function
is invoked it may already include several key/value pairs inserted by
other directive callbacks or during the
C<L<SERVER_CREATE|/C_SERVER_CREATE_>> and
C<L<DIR_CREATE|/C_DIR_CREATE_>> functions, which will be explained
later.

Usually the callback function stores the passed argument(s), which
later will be read by C<L<SERVER_MERGE|/C_SERVER_MERGE_>> and
C<L<DIR_MERGE|/C_DIR_MERGE_>>, which will be explained later, and of
course at request time.

The convention is use the name of the directive as the hash key, where
the received values are stored. The value can be a simple scalar, or a
reference to a more complex structure. So for example you can store a
reference to an array, if there is more than one value to store.

This object can be later retrieved at request time via:

  my $dir_cfg = $self->get_config($s, $r->per_dir_config);

You can retrieve the server configuration object via:

  my $srv_cfg = $self->get_config($s);

if invoked inside the virtual host, the virtual host's configuration
object will be returned.

=item 2

C<$parms> is an
C<L<Apache2::CmdParms|docs::2.0::api::Apache2::CmdParms>>
object from which you can retrieve various other information about the
configuration. For example to retrieve the server object:

  my $s = $parms->server;

See
C<L<Apache2::CmdParms|docs::2.0::api::Apache2::CmdParms>>
for more information.

=item 3

The rest of the arguments whose number depends on the
I<L<args_how|/C_args_how_>>'s value are covered in L<the next
section|/Directive_Syntax_Definition_Constants>.

=back



=head2 Directive Syntax Definition Constants

The following values of the I<L<args_how|/C_args_how_>> attribute
define how many arguments and what kind of arguments directives can
accept. These values are constants that can be imported from the
C<L<Apache2::Const|docs::2.0::api::Apache2::Const>> package
(C<L<:cmd_how constants
group|docs::2.0::api::Apache2::Const/C__cmd_how_>>).

For example:

  use Apache2::Const -compile => qw(TAKE1 TAKE23);





=head3 C<Apache2::Const::NO_ARGS>

The directive takes no arguments.  The callback will be invoked once
each time the directive is encountered.  For example:

  sub MyParameter {
      my ($self, $parms) = @_;
      $self->{MyParameter}++;
  }





=head3 C<Apache2::Const::TAKE1>

The directive takes a single argument.  The callback will be invoked
once each time the directive is encountered, and its argument will be
passed as the third argument. For example:

  sub MyParameter {
      my ($self, $parms, $arg) = @_;
      $self->{MyParameter} = $arg;
  }





=head3 C<Apache2::Const::TAKE2>

The directive takes two arguments.  They are passed to the callback as
the third and fourth arguments. For example:

  sub MyParameter {
      my ($self, $parms, $arg1, $arg2) = @_;
      $self->{MyParameter} = {$arg1 => $arg2};
  }





=head3 C<Apache2::Const::TAKE3>

This is like C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>> and
C<L<Apache2::Const::TAKE2|/C_Apache2__TAKE2_>>, but the directive takes three
mandatory arguments. For example:

  sub MyParameter {
      my ($self, $parms, @args) = @_;
      $self->{MyParameter} = \@args;
  }





=head3 C<Apache2::Const::TAKE12>

This directive takes one mandatory argument, and a second optional
one.  This can be used when the second argument has a default value
that the user may want to override.  For example:

  sub MyParameter {
      my ($self, $parms, $arg1, $arg2) = @_;
      $self->{MyParameter} = {$arg1 => $arg2||'default'};
  }





=head3 C<Apache2::Const::TAKE23>

C<L<Apache2::Const::TAKE23|/C_Apache2__TAKE23_>> is just like
C<L<Apache2::Const::TAKE12|/C_Apache2__TAKE12_>>, except now there are two
mandatory arguments and an optional third one.





=head3 C<Apache2::Const::TAKE123>

In the C<Apache2::Const::TAKE123> variant, the first argument is mandatory and
the other two are optional.  This is useful for providing defaults for
two arguments.






=head3 C<Apache2::Const::ITERATE>

C<Apache2::Const::ITERATE> is used when a directive can take an unlimited
number of arguments.  The callback is invoked repeatedly with a single
argument, once for each argument in the list.  It's done this way for
interoperability with the C API, which doesn't have the flexible
argument passing that Perl provides. For example:

  sub MyParameter {
      my ($self, $parms, $args) = @_;
      push @{ $self->{MyParameter} }, $arg;
  }






=head3 C<Apache2::Const::ITERATE2>

C<Apache2::Const::ITERATE2> is used for directives that take a mandatory first
argument followed by a list of arguments to be applied to the first.
A familiar example is the C<AddType> directive, in which a series of
file extensions are applied to a single MIME type:

  AddType image/jpeg JPG JPEG JFIF jfif

Apache will invoke your callback once for each item in the list.  Each
time Apache runs your callback, it passes the routine the constant
first argument (I<"image/jpeg"> in the example above), and the current
item in the list (I<"JPG"> the first time around, I<"JPEG"> the second
time, and so on).  In the example above, the configuration processing
routine will be run a total of four times.

For example:

  sub MyParameter {
      my ($self, $parms, $key, $val) = @_;
      push @{ $self->{MyParameter}{$key} }, $val;
  }





=head3 C<Apache2::Const::RAW_ARGS>

An I<L<args_how|/C_args_how_>> of C<Apache2::Const::RAW_ARGS> instructs
Apache to turn off parsing altogether.  Instead it simply passes your
callback function the line of text following the directive.  Leading
and trailing whitespace is stripped from the text, but it is not
otherwise processed.  Your callback can then do whatever processing it
wishes to perform.

This callback receives three arguments (similar to
C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>>), the third of which is a
string-valued scalar containing the remaining text following the
directive line.

  sub MyParameter {
      my ($self, $parms, $val) = @_;
      # process $val
  }

If this mode is used to implement a custom "container" directive, the
attribute I<L<req_override|/C_req_override_>> needs to OR
C<L<Apache2::Const::EXEC_ON_READ|/C_Apache2__Const__EXEC_ON_READ_>>. e.g.:

  req_override => Apache2::Const::OR_ALL | Apache2::Const::EXEC_ON_READ,

META: complete the details, which are new to 2.0.

To retrieve the contents of a custom "container" directive, use the
C<L<Apache2::Directive|docs::2.0::api::Apache2::Directive>> object's methods 
C<L<as_hash|docs::2.0::api::Apache2::Directive/C_as_hash_>>
or C<L<as_string|docs::2.0::api::Apache2::Directive/C_as_string_>> :

  sub MyParameter {
      my ($self, $parms, $val) = @_;
      my $directive = $parms->directive;
      my $content = $directive->as_string;
  }

There is one other trick to making configuration containers work.  In
order to be recognized as a valid directive, the I<L<name|/C_name_>>
attribute must contain the leading C<E<lt>>.  This token will be
stripped by the code that handles the custom directive callbacks to
Apache. For example:

  name     => '<MyContainer',

One other trick that is not required, but can provide some more user
friendliness is to provide a handler for the container end token.  In
our example, the Apache configuration gears will never see the
C<E<lt>/MyContainerE<gt>> token, as our
C<L<Apache2::Const::RAW_ARGS|/C_Apache2__RAW_ARGS_>> handler will read in that
line and stop reading when it is seen.  However in order to catch
cases in which the C<E<lt>/MyContainerE<gt>> text appears without a
preceding C<E<lt>MyContainerE<gt>> opening section, we need to turn
the end token into a directive that simply reports an error and
exits. For example:

  {
    name         => '</MyContainer>',
    func         => __PACKAGE__ . "::MyContainer_END",
    errmsg       => 'end of MyContainer without beginning?',
    args_how     => Apache2::Const::NO_ARGS,
    req_override => Apache2::Const::OR_ALL,
  },
  ...
  my $EndToken = "</MyContainer>";
  sub MyContainer_END {
      die "$EndToken outside a <MyContainer> container\n";
  }

Now, should the server administrator misplace the container end token, the
server will not start, complaining with this error message:

  Syntax error on line 54 of httpd.conf:
  </MyContainer> outside a <MyContainer> container




=head3 C<Apache2::Const::FLAG>

When C<Apache2::Const::FLAG> is used, Apache will only allow the argument to
be one of two values, C<On> or C<Off>.  This string value will be
converted into an integer, C<1> if the flag is C<On>, C<0> if it is
C<Off>.  If the configuration argument is anything other than C<On> or
C<Off>, Apache will complain:

  Syntax error on line 73 of httpd.conf:
  MyFlag must be On or Off

For example:

  sub MyFlag {
      my ($self, $parms, $arg) = @_;
      $self->{MyFlag} = $arg; # 1 or 0
  }










=head2 Enabling the New Configuration Directives

As seen in the first example, the module needs to be loaded before the
new directives can be used. A special directive C<PerlLoadModule> is
used for this purpose. For example:

  PerlLoadModule MyApache2::MyParameters

This directive is similar to C<PerlModule>, but it require()'s the
Perl module immediately, causing an early mod_perl startup. After
loading the module it let's Apache know of the new directives and
installs the callbacks to be called when the corresponding directives
are encountered.

=head2 Creating and Merging Configuration Objects

By default mod_perl creates a simple hash to store each container's
configuration values, which are populated by directive callbacks,
invoked when the I<httpd.conf> and the I<.htaccess> files are parsed
and the corresponding directive are encountered. It's possible to
pre-populate the hash entries when the data structure is created, e.g.,
to provide reasonable default values for cases where they weren't set
in the configuration file. To accomplish that the optional
C<L<SERVER_CREATE|/C_SERVER_CREATE_>> and
C<L<DIR_CREATE|/C_DIR_CREATE_>> functions can be supplied.

When a request is mapped to a container, Apache checks if that
container has any ancestor containers. If that's the case, it allows
mod_perl to call special merging functions, which decide whether
configurations in the parent containers should be inherited, appended
or overridden in the child container. The custom configuration module
can supply custom merging functions
C<L<SERVER_MERGE|/C_SERVER_MERGE_>> and C<L<DIR_MERGE|/C_DIR_MERGE_>>,
which can override the default behavior. If these functions are not
supplied the following default behavior takes place: The child
container inherits its parent configuration, unless it specifies its
own and then it overrides its parent configuration.

=head3 C<SERVER_CREATE>

C<SERVER_CREATE> is called once for the main server, and once more for
each virtual host defined in I<httpd.conf>. It's called with two
arguments: C<$class>, the package name it was created in and C<$parms>
the already familiar
C<L<Apache2::CmdParms|docs::2.0::api::Apache2::CmdParms>>
object. The object is expected to return a reference to a blessed
hash, which will be used by configuration directives callbacks to set
the values assigned in the configuration file. But it's possible to
preset some values here:

For example, in the following example the object assigns a default
value, which can be overridden during merge if a the directive was used
to assign a custom value:

  package MyApache2::MyParameters;
  ...
  use Apache2::Module ();
  use Apache2::CmdParms ();
  my @directives = (...);
  Apache2::Module::add(__PACKAGE__, \@directives);
  ...
  sub SERVER_CREATE {
      my ($class, $parms) = @_;
      return bless {
  	  name => __PACKAGE__,
      }, $class;
  }

To retrieve that value later, you can use:

  use Apache2::Module ();
  ...
  my $srv_cfg = Apache2::Module::get_config('MyApache2::MyParameters', $s);
  print $srv_cfg->{name};

If a request is made to a resource inside a virtual host, C<$srv_cfg>
will contain the object of the virtual host's server. To reach the
main server's configuration object use:

  use Apache2::Module ();
  use Apache2::ServerRec ();
  use Apache2::ServerUtil ();
  ...
  if ($s->is_virtual) {
      my $base_srv_cfg = Apache2::Module::get_config('MyApache2::MyParameters',
                                                    Apache2::ServerUtil->server);
      print $base_srv_cfg->{name};
  }

If the function C<SERVER_CREATE> is not supplied by the module, a
function that returns a blessed into the current package reference to
a hash is used.

=head3 C<SERVER_MERGE>

During the configuration parsing virtual hosts are given a chance to
inherit the configuration from the main host, append to or override
it. The C<SERVER_MERGE> subroutine can be supplied to override the
default behavior, which simply overrides the main server's
configuration.

The custom subroutine accepts two arguments: C<$base>, a blessed
reference to the main server configuration object, and C<$add>, a
blessed reference to a virtual host configuration object. It's
expected to return a blessed object after performing the merge of the
two objects it has received. Here is the skeleton of a merging
function:

  sub merge {
      my ($base, $add) = @_;
      my %mrg = ();
      # code to merge %$base and %$add
      return bless \%mrg, ref($base);
  }

The section L<Merging at Work|/Merging_at_Work> provides an extensive
example of a merging function.

=head3 C<DIR_CREATE>

Similarly to C<L<SERVER_CREATE|/C_SERVER_CREATE_>>, this optional
function, is used to create an object for the directory resource. If
the function is not supplied mod_perl will use an empty hash variable
as an object.

Just like C<L<SERVER_CREATE|/C_SERVER_CREATE_>>, it's called once for
the main server and one more time for each virtual host. In addition
it'll be called once more for each resource (C<E<lt>LocationE<gt>>,
C<E<lt>DirectoryE<gt>> and others). All this happens during the
startup. At request time it might be called for each parsed
I<.htaccess> file and for each resource defined in it.

The C<DIR_CREATE> function's skeleton is identical to
C<SERVER_CREATE>. Here is an example:

  package MyApache2::MyParameters;
  ...
  use Apache2::Module ();
  use Apache2::CmdParms ();
  my @directives = (...);
  Apache2::Module::add(__PACKAGE__, \@directives);
  ...
  sub DIR_CREATE {
      my ($class, $parms) = @_;
      return bless {
  	  foo => 'bar',
      }, $class;
  }

To retrieve that value later, you can use:

  use Apache2::Module ();
  ...
  my $dir_cfg = Apache2::Module::get_config('MyApache2::MyParameters',
                                           $s, $r->per_dir_config);
  print $dir_cfg->{foo};

The only difference in the retrieving the directory configuration
object. Here the third argument C<$r-E<gt>per_dir_config> tells
C<L<Apache2::Module|docs::2.0::api::Apache2::Module>> to
get the directory configuration object.

=head3 C<DIR_MERGE>

Similarly to C<L<SERVER_MERGE|/C_SERVER_MERGE_>>, C<DIR_MERGE> merges
the ancestor and the current node's directory configuration objects.
At the server startup C<DIR_MERGE> is called once for each virtual
host. At request time, the merging of the objects of resources, their
sub-resources and the virtual host/main server merge happens. Apache
caches the products of merges, so you may see certain merges happening
only once.

The section L<Merging Order Consequences|/Merging_Order_Consequences>
discusses in detail the merging order.

The section L<Merging at Work|/Merging_at_Work> provides an extensive
example of a merging function.

=head1 Examples

=head2 Merging at Work

In the following example we are going to demonstrate in details how
merging works, by showing various merging techniques.

Here is an example Perl module, which, when loaded, installs four
custom directives into Apache.

  #file:MyApache2/CustomDirectives.pm
  #---------------------------------
  package MyApache2::CustomDirectives;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache2::CmdParms ();
  use Apache2::Module ();
  use Apache2::ServerUtil ();
  
  use Apache2::Const -compile => qw(OK);
  
  my @directives = (
      { name => 'MyPlus' },
      { name => 'MyList' },
      { name => 'MyAppend' },
      { name => 'MyOverride' },
  );
  Apache2::Module::add(__PACKAGE__, \@directives);
  
  sub MyPlus     { set_val('MyPlus',     @_) }
  sub MyAppend   { set_val('MyAppend',   @_) }
  sub MyOverride { set_val('MyOverride', @_) }
  sub MyList     { push_val('MyList',    @_) }
  
  sub DIR_MERGE    { merge(@_) }
  sub SERVER_MERGE { merge(@_) }
  
  sub set_val {
      my ($key, $self, $parms, $arg) = @_;
      $self->{$key} = $arg;
      unless ($parms->path) {
          my $srv_cfg = Apache2::Module::get_config($self,
                                                   $parms->server);
          $srv_cfg->{$key} = $arg;
      }
  }
  
  sub push_val {
      my ($key, $self, $parms, $arg) = @_;
      push @{ $self->{$key} }, $arg;
      unless ($parms->path) {
          my $srv_cfg = Apache2::Module::get_config($self,
                                                   $parms->server);
          push @{ $srv_cfg->{$key} }, $arg;
      }
  }
  
  sub merge {
      my ($base, $add) = @_;
  
      my %mrg = ();
      for my $key (keys %$base, keys %$add) {
          next if exists $mrg{$key};
          if ($key eq 'MyPlus') {
              $mrg{$key} = ($base->{$key}||0) + ($add->{$key}||0);
          }
          elsif ($key eq 'MyList') {
              push @{ $mrg{$key} },
                  @{ $base->{$key}||[] }, @{ $add->{$key}||[] };
          }
          elsif ($key eq 'MyAppend') {
              $mrg{$key} = join " ", grep defined, $base->{$key},
                                                   $add->{$key};
          }
          else {
              # override mode
              $mrg{$key} = $base->{$key} if exists $base->{$key};
              $mrg{$key} = $add->{$key}  if exists $add->{$key};
          }
      }
  
      return bless \%mrg, ref($base);
  }
  
  1;
  __END__

It's probably a good idea to specify all the attributes for the
C<@directives> entries, but here for simplicity we have
only assigned to the I<L<name|/C_name_>> directive, which is a
must. Since all our directives take a single argument,
C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>>, the default
I<L<args_how|/C_args_how_>>, is what we need. We also allow the
directives to appear anywhere, so
C<L<Apache2::Const::OR_ALL|/C_Apache2__OR_ALL_>>, the default for
I<L<req_override|/C_req_override_>>, is good for us as well.

We use the same callback for the directives C<MyPlus>, C<MyAppend> and
C<MyOverride>, which simply assigns the specified value to the hash
entry with the key of the same name as the directive.

The C<MyList> directive's callback stores the value in the list, a
reference to which is stored in the hash, again using the name of the
directive as the key. This approach is usually used when the directive
is of type C<L<Apache2::Const::ITERATE|/C_Apache2__ITERATE_>>, so you may have
more than one value of the same kind inside a single container. But in
our example we choose to have it of the type
C<L<Apache2::Const::TAKE1|/C_Apache2__TAKE1_>>.

In both callbacks in addition to storing the value in the current
I<directory> configuration, if the value is configured in the main
server or the virtual host (which is when C<$parms-E<gt>path> is
false), we also store the data in the same way in the server
configuration object. This is done in order to be able to query the
values assigned at the server and virtual host levels, when the
request is made to one of the sub-resources. We will show how to
access that information in a moment.

Finally we use the same merge function for merging directory and
server configuration objects. For the key C<MyPlus> (remember we have
used the same key name as the name of the directive), the merging
function performs, the obvious, summation of the ancestor's merged
value (base) and the current resource's value (add). C<MyAppend> joins
the values into a string, C<MyList> joins the lists and finally
C<MyOverride> (the default) overrides the value with the current one
if any. Notice that all four merging methods take into account that
the values in the ancestor or the current configuration object might
be unset, which is the case when the directive wasn't used by all
ancestors or for the current resource.

At the end of the merging, a blessed reference to the merged hash is
returned. The reference is blessed into the same class, as the base or
the add objects, which is C<MyApache2::CustomDirectives> in our
example. That hash is used as the merged ancestor's object for a
sub-resource of the resource that has just undergone merging.

Next we supply the following I<httpd.conf> configuration section, so
we can demonstrate the features of this example:

  PerlLoadModule MyApache2::CustomDirectives
  MyPlus 5
  MyList     "MainServer"
  MyAppend   "MainServer"
  MyOverride "MainServer"
  Listen 8081
  <VirtualHost _default_:8081>
      MyPlus 2
      MyList     "VHost"
      MyAppend   "VHost"
      MyOverride "VHost"
      <Location /custom_directives_test>
          MyPlus 3
          MyList     "Dir"
          MyAppend   "Dir"
          MyOverride "Dir"
          SetHandler modperl
          PerlResponseHandler MyApache2::CustomDirectivesTest
      </Location>
      <Location /custom_directives_test/subdir>
          MyPlus 1
          MyList     "SubDir"
          MyAppend   "SubDir"
          MyOverride "SubDir"
      </Location>
  </VirtualHost>
  <Location /custom_directives_test>
      SetHandler modperl
      PerlResponseHandler MyApache2::CustomDirectivesTest
  </Location>

C<PerlLoadModule> loads the Perl module C<MyApache2::CustomDirectives>
and then installs a new Apache module named
C<MyApache2::CustomDirectives>, using the callbacks provided by the
Perl module.  In our example functions C<SERVER_CREATE> and
C<DIR_CREATE> aren't provided, so by default an empty hash will be
created to represent the configuration object for the merging
functions. If we don't provide merging functions, Apache will simply
skip the merging. Though you must provide a callback function for each
directive you add.

After installing the new module, we add a virtual host container,
containing two resources (which at other times called locations,
directories, sections, etc.), one being a sub-resource of the other,
plus one another resource which resides in the main server.

We assign different values in all four containers, but the last
one. Here we refer to the four containers as I<MainServer>, I<VHost>,
I<Dir> and I<SubDir>, and use these names as values for all
configuration directives, but C<MyPlus>, to make it easier understand
the outcome of various merging methods and the merging order. In the
last container used by C<E<lt>Location /custom_directives_testE<gt>>,
we don't specify any directives so we can verify that all the values
are inherited from the main server.

For all three resources we are going to use the same response handler,
which will dump the values of configuration objects that in its
reach. As we will see that different resources will see see certain
things identically, while others differently. So here it the handler:

  #file:MyApache2/CustomDirectivesTest.pm
  #-------------------------------------
  package MyApache2::CustomDirectivesTest;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache2::RequestRec ();
  use Apache2::RequestIO ();
  use Apache2::ServerRec ();
  use Apache2::ServerUtil ();
  use Apache2::Module ();
  
  use Apache2::Const -compile => qw(OK);
  
  sub get_config {
      Apache2::Module::get_config('MyApache2::CustomDirectives', @_);
  }
  
  sub handler {
      my ($r) = @_;
      my %secs = ();
  
      $r->content_type('text/plain');
  
      my $s = $r->server;
      my $dir_cfg = get_config($s, $r->per_dir_config);
      my $srv_cfg = get_config($s);
  
      if ($s->is_virtual) {
          $secs{"1: Main Server"}  = get_config(Apache2::ServerUtil->server);
          $secs{"2: Virtual Host"} = $srv_cfg;
          $secs{"3: Location"}     = $dir_cfg;
      }
      else {
          $secs{"1: Main Server"}  = $srv_cfg;
          $secs{"2: Location"}     = $dir_cfg;
       }
  
      $r->printf("Processing by %s.\n", 
          $s->is_virtual ? "virtual host" : "main server");
  
      for my $sec (sort keys %secs) {
          $r->print("\nSection $sec\n");
          for my $k (sort keys %{ $secs{$sec}||{} }) {
              my $v = exists $secs{$sec}->{$k}
                  ? $secs{$sec}->{$k}
                  : 'UNSET';
              $v = '[' . (join ", ", map {qq{"$_"}} @$v) . ']'
                  if ref($v) eq 'ARRAY';
              $r->printf("%-10s : %s\n", $k, $v);
          }
      }
  
      return Apache2::Const::OK;
  }
  
  1;
  __END__

The handler is relatively simple. It retrieves the current resource
(directory) and the server's configuration objects. If the server is a
virtual host, it also retrieves the main server's configuration
object. Once these objects are retrieved, we simply dump the contents
of these objects, so we can verify that our merging worked
correctly. Of course we nicely format the data that we print, taking a
special care of array references, which we know is the case with the
key I<MyList>, but we use a generic code, since Perl tells us when a
reference is a list.

It's a show time. First we issue a request to a resource residing in
the main server:

  % GET http://localhost:8002/custom_directives_test/
  
  Processing by main server.
  
  Section 1: Main Server
  MyAppend   : MainServer
  MyList     : ["MainServer"]
  MyOverride : MainServer
  MyPlus     : 5
  
  Section 2: Location
  MyAppend   : MainServer
  MyList     : ["MainServer"]
  MyOverride : MainServer
  MyPlus     : 5

Since we didn't have any directives in that resource's configuration,
we confirm that our merge worked correctly and the directory
configuration object contains the same data as its ancestor, the main
server. In this case the merge has simply inherited the values from
its ancestor.

The next request is for the resource residing in the virtual host:

  % GET http://localhost:8081/custom_directives_test/
  
  Processing by virtual host.
  
  Section 1: Main Server
  MyAppend   : MainServer
  MyList     : ["MainServer"]
  MyOverride : MainServer
  MyPlus     : 5
  
  Section 2: Virtual Host
  MyAppend   : MainServer VHost
  MyList     : ["MainServer", "VHost"]
  MyOverride : VHost
  MyPlus     : 7
  
  Section 3: Location
  MyAppend   : MainServer VHost Dir
  MyList     : ["MainServer", "VHost", "Dir"]
  MyOverride : Dir
  MyPlus     : 10

That's where the real fun starts. We can see that the merge worked
correctly in the virtual host, and so it did inside the
C<E<lt>LocationE<gt>> resource. It's easy to see that C<MyAppend> and
C<MyList> are correct, the same for C<MyOverride>. For C<MyPlus>, we
have to work harder and perform some math. Inside the virtual host we
have main(5)+vhost(2)=7, and inside the first resource
vhost_merged(7)+resource(3)=10.

So far so good, the last request is made to the sub-resource of the
resource we have requested previously:

  % GET http://localhost:8081/custom_directives_test/subdir/
  
  Processing by virtual host.
  
  Section 1: Main Server
  MyAppend   : MainServer
  MyList     : ["MainServer"]
  MyOverride : MainServer
  MyPlus     : 5
  
  Section 2: Virtual Host
  MyAppend   : MainServer VHost
  MyList     : ["MainServer", "VHost"]
  MyOverride : VHost
  MyPlus     : 7
  
  Section 3: Location
  MyAppend   : MainServer VHost Dir SubDir
  MyList     : ["MainServer", "VHost", "Dir", "SubDir"]
  MyOverride : SubDir
  MyPlus     : 11

No surprises here. By comparing the configuration sections and the
outcome, it's clear that the merging is correct for most
directives. The only harder verification is for C<MyPlus>, all we need
to do is to add 1 to 10, which was the result we saw in the previous
request, or to do it from scratch, summing up all the ancestors of
this sub-resource: 5+2+3+1=11.


=head3 Merging Entries Whose Values Are References

When merging entries whose values are references and not scalars, it's
important to make a deep copy and not a shallow copy, when the
references gets copied. In our example we merged two references to
lists, by explicitly extracting the values of each list:

  push @{ $mrg{$key} },
      @{ $base->{$key}||[] }, @{ $add->{$key}||[] };

While seemingly the following snippet is doing the same:

  $mrg{$key} = $base->{$key};
  push @{ $mrg{$key} }, @{ $add->{$key}||[] };

it won't do what you expect if the same merge (with the same C<$base>
and C<$add> arguments) is called more than once, which is the case in
certain cases. What happens in the latter implementation, is that the
first line makes both C<$mrg{$key}> and C<$base-E<gt>{$key}> point to
the same reference. When the second line expands the C<@{ $mrg{$key}
}>, it also affects C<@{ $base-E<gt>{$key} }>. Therefore when the same
merge is called second time, the C<$base> argument is not the same
anymore.

Certainly we could workaround this problem in the mod_perl core, by
freezing the arguments before the merge call and restoring them
afterwards, but this will incur a performance hit. One simply has to
remember that the arguments and the references they point to, should
stay unmodified through the function call, and then the right code can
be supplied.

=head3 Merging Order Consequences

Sometimes the merging logic can be influenced by the order of merging.
It's desirable that the logic will work properly regardless of the
merging order.

In Apache 1.3 the merging was happening in the following order:

  (((base_srv -> vhost) -> section) -> subsection)

Whereas as of this writing Apache 2.0 performs:

  ((base_srv -> vhost) -> (section -> subsection))

A product of subsections merge (which happen during the request) is
merged with the product of the server and virtual host merge (which happens
at the startup time). This change was done to improve the
configuration merging performance.

So for example, if you implement a directive C<MyExp> which performs
the exponential: C<$mrg=$base**$add>, and let's say there directive is
used four times in I<httpd.conf>:

  MyExp 5
  <VirtualHost _default_:8001>
       MyExp 4
       <Location /section>
           MyExp 3
       </Location>
       <Location /section/subsection>
           MyExp 2
       </Location>

The merged configuration for a request
I<http://localhost:8001/section/subsection> will see:

  (5 ** 4) ** (3 ** 2)  = 1.45519152283669e+25

under Apache 2.0, whereas under Apache 1.3 the result would be:

  ( (5 ** 4) ** 3) ** 2 = 5.96046447753906e+16

which is not quite the same.

Chances are that your merging rules work identically, regardless of
the merging order. But you should be aware of this behavior.


=head1 Maintainers

Maintainer is the person(s) you should contact with updates,
corrections and patches.

=over

=item *

Stas Bekman [http://stason.org/]

=back

=head1 Authors

=over

=item *

Stas Bekman [http://stason.org/]

=back

Only the major authors are listed above. For contributors see the
Changes file.

=cut