ASP/ModPerl.pm untested

filter: Statementstmt 0.0% 0 / 73 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 109 CC 10 SCAR 39.8
CC
10
Cov
0%
handler
110.0
BEGIN
2.0
BEGIN
2.0
CRAP 53.4
1  
2 package Apache2::ASP::ModPerl;
3  
4 use strict;
5 use warnings 'all';
6 use APR::Table ();
7 use APR::Socket ();
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10 use Apache2::Connection ();
11 use Apache2::RequestUtil ();
12 use Apache2::ASP::HTTPContext ();
13 use CGI();
14 use Apache2::ASP::UploadHook;
15  
16 local $Apache2::ASP::HTTPContext::ClassName = 'Apache2::ASP::HTTPContext';
17  
18  
19 #==============================================================================
20 sub handler : method
21 {
22 my ($class, $r) = @_;
23
24 my $context = Apache2::ASP::HTTPContext->new();
25
26 if( uc($r->method) eq 'POST' && $r->headers_in->{'content-type'} =~ m/multipart\/form\-data/ )
27 {
28 $context->{r} = $r;
29 eval {
30 $context->_load_class( $context->config->web->handler_resolver );
31 };
32 if( $@ )
33 {
34 warn $@;
35 $r->status( 500 );
36 return $r->status;
37 }# end if()
38
39 my $handler_class = eval {
40 $context->config->web->handler_resolver->new()->resolve_request_handler( $r->uri )
41 };
42 if( $@ )
43 {
44 warn $@;
45 $r->status( 500 );
46 return $r->status;
47 }# end if()
48
49 return 404 unless $handler_class;
50
51 eval {
52 $context->_load_class( $handler_class );
53
54 my $cgi = CGI->new( $r );
55 my %args = map { my ($k,$v) = split /\=/, $_; ( $k => $v ) } split /&/, $ENV{QUERY_STRING};
56 map { $cgi->param($_ => $args{$_}) } keys %args;
57 $context->setup_request( $r, $cgi);
58 $handler_class->init_asp_objects( $context );
59
60 $context->execute;
61 };
62 if( $@ )
63 {
64 warn $@;
65 $r->status( 500 );
66 }# end if()
67 return $r->status =~ m/^2/ ? 0 : $r->status;
68 }
69 else
70 {
71 my $cgi = CGI->new( $r );
72 eval {
73 $context->setup_request( $r, $cgi );
74 $context->execute;
75 };
76 warn $@ if $@;
77
78 return 500 if $@;
79 return $r->status =~ m/^2/ ? 0 : $r->status;
80 }# end if()
81
82 }# end handler()
83  
84 1;# return true:
85  
86 =pod
87  
88 =head1 NAME
89  
90 Apache2::ASP::ModPerl - mod_perl2 PerlResponseHandler for Apache2::ASP
91  
92 =head1 SYNOPSIS
93  
94 In your httpd.conf
95
96 # Needed for file uploads to work properly:
97 LoadModule apreq_module modules/mod_apreq2.so
98  
99 # Load up some important modules:
100 PerlModule DBI
101 PerlModule DBD::mysql
102 PerlModule Apache2::ASP::ModPerl
103  
104 # Admin website:
105 <VirtualHost *:80>
106  
107 ServerName mysite.com
108 ServerAlias www.mysite.com
109 DocumentRoot /usr/local/projects/mysite.com/htdocs
110
111 # Set the directory index:
112 DirectoryIndex index.asp
113
114 # All *.asp files are handled by Apache2::ASP::ModPerl
115 <Files ~ (\.asp$)>
116 SetHandler perl-script
117 PerlResponseHandler Apache2::ASP::ModPerl
118 </Files>
119
120 # !IMPORTANT! Prevent anyone from viewing your GlobalASA.pm
121 <Files ~ (\.pm$)>
122 Order allow,deny
123 Deny from all
124 </Files>
125
126 # All requests to /handlers/* will be handled by their respective handler:
127 <Location /handlers>
128 SetHandler perl-script
129 PerlResponseHandler Apache2::ASP::ModPerl
130 </Location>
131
132 </VirtualHost>
133  
134 =head1 DESCRIPTION
135  
136 C<Apache2::ASP::ModPerl> provides a mod_perl2 PerlResponseHandler interface to
137 L<Apache2::ASP::HTTPContext>.
138  
139 Under normal circumstances, all you have to do is configure it and forget about it.
140  
141 =head1 BUGS
142  
143 It's possible that some bugs have found their way into this release.
144  
145 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
146  
147 =head1 HOMEPAGE
148  
149 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
150 of Apache2::ASP in action.
151  
152 =head1 AUTHOR
153  
154 John Drago L<mailto:jdrago_999@yahoo.com>
155  
156 =head1 COPYRIGHT AND LICENSE
157  
158 Copyright 2007 John Drago, All rights reserved.
159  
160 This software is free software. It may be used and distributed under the
161 same terms as Perl itself.
162  
163 =cut
164