Changeset 52

Show
Ignore:
Timestamp:
11/04/09 18:10:58 (4 years ago)
Author:
clinton
Message:

Documentation for MungoPreamble? feature, tid10737

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Mungo.pm

    r51 r52  
    1010 <FilesMatch "\.asp$"> 
    1111   SetHandler perl-script 
     12 
    1213   PerlHandler Mungo 
     14 
     15   # This is optional, see PREAMBLE SUPPORT below 
     16   PerlSetVar MungoPreamble My::PreambleHandler 
     17 
    1318 </FilesMatch> 
    1419 
     
    157162setting PerlHandler Mungo in your httpd.conf file). 
    158163 
     164 
     165=head2 Preamble Support 
     166 
     167In addition to normal Apache stacked handlers, Mungo also supports a  
     168mechanism for inserting code to execute before every Mungo request is  
     169processed, while still having access to the Mungo environment. 
     170 
     171To use this mechanism, define a Perl module as follows: 
     172 
     173  package My::PreambleHandler; 
     174  use strict; 
     175  use warnings; 
     176 
     177  use Apache2::Const qw ( OK DECLINED ); # Others as needed by your code 
     178 
     179  sub handler { 
     180     my $class          = shift; 
     181     my $apache_request = shift; 
     182     my $mungo_request  = shift; 
     183     my $mungo_response = shift; 
     184     my $mungo_server   = shift; 
     185 
     186     # Determine what to do with the request, if anything 
     187 
     188     if ( ... ) { 
     189         # Continue normal Mungo processing 
     190         return Apache2::Const::DECLINED; 
     191 
     192     } elsif ( ... ) { 
     193         # If handled entirely within the preamble, skip further Mungo work 
     194         return Apache2::Const::OK; 
     195 
     196     } elsif ( ... ) { 
     197         # Returning anything other than DECLINED will  
     198         # skip further Mungo work - but should be informative 
     199         # for example, if the user's credentials are bad... 
     200         return Apache2::Const::NOT_AUTHORIZED; 
     201     } 
     202 
     203  } 
     204 
     205With your preamble code in hand, you may now register this code to run on a per-location, directory, or file basis: 
     206 
     207  <Location /restricted> 
     208    SetHandler perl-script 
     209    PerlSetVar MungoPreamble My::AuthorizationCheckingPreamble 
     210    PerlHandler Mungo 
     211  </location> 
     212 
     213=head3 Limitations of Preambles 
     214 
     215=over 
     216 
     217=item Limit of one Preamble per location/file/directory stanza 
     218 
     219If you require more flexibility, Apache stacked handlers are likely a better solution for you (though you will not have the Mungo environment setup in your stacked handler). 
     220 
     221=item Preambles Modules will not be automatically loaded 
     222 
     223You can add a PerlRequire directive to httpd.conf, or 'use' your preamble class in your startup.pl 
     224 
     225=back 
     226 
    159227=cut 
     228 
    160229 
    161230 
     
    172241  use Apache2::RequestRec; 
    173242  use Apache2::RequestUtil; 
    174   use Apache2::Const qw ( OK NOT_FOUND ); 
     243  use Apache2::Const qw ( OK NOT_FOUND DECLINED ); 
    175244"; 
    176245if($@) {