59 | | Each Apache module is responsible for defining and creating its own configuration data structures. When Apache asks an HLL module for a server or directory configuration, mod_parrot will look for a subroutine in the {{{ModParrot;HLL;hllname}}} namespace to execute. Server configs are provided by {{{server_create}}}, while directory configs are provided by {{{dir_create}}}. These subroutines should create a data structure, possibly populated with default values, and return it. The type of the structure is up to the implementor, as long as it is a valid Parrot PMC. |
| 59 | Each Apache module is responsible for defining and creating its own configuration data structures. When Apache asks an HLL module for a server or directory configuration, mod_parrot will look for a "constructor" subroutine in the {{{ModParrot;HLL;hllname}}} namespace to execute. Server configs are provided by {{{server_create}}}, while directory configs are provided by {{{dir_create}}}. These subroutines should create a data structure, possibly populated with default values, and return it. The type of the structure is up to the implementor, as long as it is a valid Parrot PMC. |
| 83 | |
| 84 | Like the constructor subroutines above, HLL modules can provide subroutines to merge two configurations. This is useful when, for example, a particular configuration setting for a directory should be overridden by a different setting in a subdirectory. Or perhaps your HLL is maintaining an array of values for a virtual host that should be concatenated with the array defined in the main server. All of this behavior is performed by the merge subroutines. |
| 85 | |
| 86 | The server merge subroutine is called {{{server_merge}}}, and the directory merge is handled by {{{dir_merge}}}. They are passed the "base" configuration and the "new" configuration, and are expected to return a merged configuration. These subroutines should create a new PMC for the merged configuration rather than reusing the PMC from the "new" configuration. Parrot passes PMCs by reference, and the code would thus be changing the "new" configuration directly, resulting in unexpected behavior. |
| 87 | |
| 88 | ''Signatures'' |
| 89 | |
| 90 | * {{{PMC server_merge(PMC basecfg, PMC newcfg)}}} |
| 91 | * {{{PMC dir_merge(PMC basecfg, PMC newcfg)}}} |
| 92 | |
| 93 | ''Example: A self-hosted server merge from mod_perl6'' |
| 94 | |
| 95 | {{{ |
| 96 | sub server_merge(%base, %new) |
| 97 | { |
| 98 | my %merged; |
| 99 | |
| 100 | # merge handlers -- never inherit |
| 101 | for @server_phases.map({$_ ~ '_handler'}) -> $h { |
| 102 | %merged{$h} = %new{$h}; |
| 103 | } |
| 104 | |
| 105 | return %merged; |
| 106 | } |
| 107 | }}} |