blib/lib/ASP4/TransHandler.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 35 CC 1 SCAR 6.9
CC
1
Cov
0%
handler
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1  
2
3 package ASP4::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 $ENV{REMOTE_ADDR} = $r->connection->get_remote_host();
21 $ENV{HTTP_HOST} = $r->hostname;
22
23 return -1;
24 }# end handler()
25  
26 1;# return true:
27  
28 =pod
29  
30 =head1 NAME
31  
32 ASP4::TransHandler - PerlTransHandler with access to ASP4::Config
33  
34 =head1 SYNOPSIS
35  
36 package My::TransHandler;
37
38 use strict;
39 use warnings 'all';
40 use base 'ASP4::TransHandler';
41 use ASP4::ConfigLoader;
42
43 sub handler : method {
44 my ($class, $r) = @_;
45
46 my $super_response = $class->SUPER::handler( $r );
47
48 my $config = ASP4::ConfigLoader->load();
49
50 # Do stuff...
51 calculate_pi_to_the_billionth_decimal_place();
52
53 # Finally...
54 return $super_response;
55 }
56
57 1;# return true:
58  
59 Then, in your httpd.conf:
60  
61 <Perl>
62 push @INC, '/path/to/your/libs';
63 </Perl>
64  
65 <VirtualHost *:80>
66 ...
67 PerlTransHandler My::TransHandler
68 ...
69 </VirtualHost>
70  
71 =head1 DESCRIPTION
72  
73 C<ASP4::TransHandler> is a utility class that helps module authors take advantage
74 of the ASP4 configuration without actually doing any of the work.
75  
76 =head2 RequestFilters vs TransHandlers
77  
78 The difference between TransHandlers and L<ASP4::RequestFilter>s is that
79 within a RequestFilter, you have access to all of the normal ASP objects ($Request, $Response, $Session, etc).
80  
81 In a TransHandler, you only have access to the L<Apache2::RequestRec> C<$r> and the
82 L<ASP4::Config> (and only then if you load it up yourself via L<ASP4::ConfigLoader>.
83  
84 B<NOTE>: - TransHandlers are configured in the C<httpd.conf> and are only executed
85 in a real Apache2 httpd environment. They are not executed during testing or via
86 L<ASP4::API>.
87  
88 TransHandlers are a handy way of jumping into "normal" mod_perl handler mode without
89 losing access to your web application's config.
90  
91 =head1 BUGS
92  
93 It's possible that some bugs have found their way into this release.
94  
95 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ASP4> to submit bug reports.
96  
97 =head1 HOMEPAGE
98  
99 Please visit the ASP4 homepage at L<http://0x31337.org/code/> to see examples
100 of ASP4 in action.
101  
102 =cut
103  
104