| 1 | |||
| 2 | |||
| 3 | package Apache2::ASP::TransHandler; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use APR::Table (); | ||
| 7 | use Apache2::RequestRec (); | ||
| 8 | use Apache2::RequestUtil (); | ||
| 9 | use Apache2::SubRequest (); | ||
| 10 | use Apache2::Const -compile => ':common'; | ||
| 11 | use Apache2::ServerRec (); | ||
| 12 | |||
| 13 | |||
| 14 | #============================================================================== | ||
| 15 | sub handler : method | ||
| 16 | { | ||
| 17 | my ($class, $r) = @_; | ||
| 18 | |||
| 19 | $ENV{DOCUMENT_ROOT} ||= $r->document_root; | ||
| 20 | |||
| 21 | return -1; | ||
| 22 | }# end handler() | ||
| 23 | |||
| 24 | 1;# return true: | ||
| 25 | |||
| 26 | =pod | ||
| 27 | |||
| 28 | =head1 NAME | ||
| 29 | |||
| 30 | Apache2::ASP::TransHandler - PerlTransHandler with access to Apache2::ASP::Config | ||
| 31 | |||
| 32 | =head1 SYNOPSIS | ||
| 33 | |||
| 34 | package My::TransHandler; | ||
| 35 | |||
| 36 | use strict; | ||
| 37 | use warnings 'all'; | ||
| 38 | use base 'Apache2::ASP::TransHandler'; | ||
| 39 | use Apache2::ASP::ConfigLoader; | ||
| 40 | |||
| 41 | sub handler : method { | ||
| 42 | my ($class, $r) = @_; | ||
| 43 | |||
| 44 | my $super_response = $class->SUPER::handler( $r ); | ||
| 45 | |||
| 46 | my $config = Apache2::ASP::ConfigLoader->load(); | ||
| 47 | |||
| 48 | # Do stuff... | ||
| 49 | calculate_pi_to_the_billionth_decimal_place(); | ||
| 50 | |||
| 51 | # Finally... | ||
| 52 | return $super_response; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1;# return true: | ||
| 56 | |||
| 57 | Then, in your httpd.conf: | ||
| 58 | |||
| 59 | <Perl> | ||
| 60 | push @INC, '/path/to/your/libs'; | ||
| 61 | </Perl> | ||
| 62 | |||
| 63 | <VirtualHost *:80> | ||
| 64 | ... | ||
| 65 | PerlTransHandler My::TransHandler | ||
| 66 | ... | ||
| 67 | </VirtualHost> | ||
| 68 | |||
| 69 | =head1 DESCRIPTION | ||
| 70 | |||
| 71 | C<Apache2::ASP::TransHandler> is | ||
| 72 | |||
| 73 | =head2 RequestFilters vs TransHandlers | ||
| 74 | |||
| 75 | The difference between TransHandlers and L<Apache2::ASP::RequestFilter>s is that | ||
| 76 | within a RequestFilter, you have access to all of the normal ASP objects ($Request, $Response, $Session, etc). | ||
| 77 | |||
| 78 | In a TransHandler, you only have access to the L<Apache2::RequestRec> C<$r> and the | ||
| 79 | L<Apache2::ASP::Config> (and only then if you load it up yourself via L<Apache2::ASP::ConfigLoader>. | ||
| 80 | |||
| 81 | B<NOTE>: - TransHandlers are configured in the C<httpd.conf> and are only executed | ||
| 82 | in a real Apache2 httpd environment. They are not executed during testing or via | ||
| 83 | L<Apache2::ASP::API>. | ||
| 84 | |||
| 85 | TransHandlers are a handy way of jumping into "normal" mod_perl handler mode without | ||
| 86 | losing access to your web application's config. | ||
| 87 | |||
| 88 | =head1 BUGS | ||
| 89 | |||
| 90 | It's possible that some bugs have found their way into this release. | ||
| 91 | |||
| 92 | Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports. | ||
| 93 | |||
| 94 | =head1 HOMEPAGE | ||
| 95 | |||
| 96 | Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples | ||
| 97 | of Apache2::ASP in action. | ||
| 98 | |||
| 99 | =head1 AUTHOR | ||
| 100 | |||
| 101 | John Drago <jdrago_999@yahoo.com> | ||
| 102 | |||
| 103 | =head1 COPYRIGHT AND LICENSE | ||
| 104 | |||
| 105 | Copyright 2007 John Drago, All rights reserved. | ||
| 106 | |||
| 107 | This software is free software. It may be used and distributed under the | ||
| 108 | same terms as Perl itself. | ||
| 109 | |||
| 110 | =cut | ||
| 111 |