| 273 | === Return Values === |
| 274 | |
| 275 | The return value from a metahandler is passed directly back to Apache, and should be a valid Apache or HTTP status code. Constants for these codes are available from the {{{ModParrot;Apache;Constants;table}}} hash from {{{ModParrot/Apache/Constants.pbc}}}. Please refer to the Apache documentation for details on how each phase reacts to different status codes. |
| 276 | |
| 277 | === Example Metahandlers === |
| 278 | |
| 279 | ''The PIR HLL module response handler'' |
| 280 | {{{ |
| 281 | # response handler |
| 282 | .sub response_handler |
| 283 | .param pmc ctx |
| 284 | .local pmc r, handler, cfg, dircfg, get_config, ap_const |
| 285 | .local int status |
| 286 | |
| 287 | ap_const = get_root_global ['ModParrot'; 'Apache'; 'Constants'], 'table' |
| 288 | |
| 289 | # get the request_rec object |
| 290 | r = ctx.'request_rec'() |
| 291 | |
| 292 | # decline if not our handler |
| 293 | $S0 = r.'handler'() |
| 294 | if $S0 == 'parrot-code' goto get_configs |
| 295 | status = ap_const['DECLINED'] |
| 296 | goto return_status |
| 297 | |
| 298 | get_configs: |
| 299 | get_config = get_hll_global ['ModParrot'; 'Apache'; 'Module'], 'get_config' |
| 300 | cfg = get_config('modparrot_pir_module') |
| 301 | $P0 = r.'per_dir_config'() |
| 302 | dircfg = get_config('modparrot_pir_module', $P0) |
| 303 | |
| 304 | # decline if we have no config in this section |
| 305 | unless null dircfg goto get_handler |
| 306 | status = ap_const['DECLINED'] |
| 307 | .return(status) |
| 308 | |
| 309 | get_handler: |
| 310 | # decline if we have no handler in this section |
| 311 | $S0 = dircfg['response_handler'] |
| 312 | if $S0 goto run_handler |
| 313 | status = ap_const['DECLINED'] |
| 314 | .return(status) |
| 315 | |
| 316 | run_handler: |
| 317 | # set our default content type |
| 318 | r.'content_type'('text/html') |
| 319 | # find the handler sub and call it |
| 320 | $P0 = split ';', $S0 |
| 321 | get_hll_global handler, $P0, 'handler' |
| 322 | status = handler(r) |
| 323 | |
| 324 | return_status: |
| 325 | .return(status) |
| 326 | .end |
| 327 | }}} |
| 328 | |
| 329 | ''The mod_perl6 response handler'' |
| 330 | {{{ |
| 331 | sub response_handler($ctx) |
| 332 | { |
| 333 | my $r = $ctx.request_rec(); |
| 334 | |
| 335 | unless ($r.handler() ~~ any(<modperl6 perl6-script>)) { |
| 336 | return $Apache::Const::DECLINED; |
| 337 | } |
| 338 | |
| 339 | my %cfg = ModParrot::Apache::Module::get_config("modparrot_perl6_module"); |
| 340 | my %dircfg = ModParrot::Apache::Module::get_config("modparrot_perl6_module", |
| 341 | $r.per_dir_config()); |
| 342 | |
| 343 | my $handler = %dircfg<response_handler>; |
| 344 | |
| 345 | $r.content_type('text/html'); |
| 346 | my $status = call_handler($handler, $r); |
| 347 | return $status; |
| 348 | } |
| 349 | }}} |