ASP/ASPHandler.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 89 CC 9 SCAR 38.8
CC
9
Cov
0%
run
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 48.6
1  
2 package Apache2::ASP::ASPHandler;
3  
4 use strict;
5 use warnings 'all';
6 use base 'Apache2::ASP::HTTPHandler';
7 use Carp 'confess';
8 use vars __PACKAGE__->VARS;
9  
10 use Data::Dumper;
11  
12 #==============================================================================
13 sub run
14 {
15 my ($s, $context, $args) = @_;
16
17 $s->init_asp_objects( $context );
18  
19 # Find the page:
20 $ENV{SCRIPT_FILENAME} .= 'index.asp'
21 unless $ENV{SCRIPT_FILENAME} =~ m/\.asp$/;
22 $ENV{SCRIPT_NAME} .= 'index.asp'
23 unless $ENV{SCRIPT_NAME} =~ m/\.asp$/;
24 my $asp_filename = $Request->ServerVariables('SCRIPT_FILENAME')
25 or return;
26 my $cache_root = $Config->web->page_cache_root;
27 my $web_root = $Config->web->www_root;
28 (my $pm_filename = $asp_filename) =~ s/^\Q$web_root\E\///; # =~ m/([^\/]+)$/;
29 $pm_filename =~ s/[^a-z0-9_]/_/ig;
30 $pm_filename .= ".pm";
31 my $pm_folder = $cache_root . '/' . $Config->web->application_name;
32 my $pm_path = $pm_folder . '/' . $pm_filename;
33 mkdir( $pm_folder ) unless -d $pm_folder;
34 my $pkg_path = $Config->web->application_name . '/' . $pm_filename;
35
36 push @INC, $cache_root unless grep { $_ eq $cache_root } @INC;
37 if( -f $asp_filename )
38 {
39 (my $pkg_name = $pkg_path) =~ s/\//::/g;
40 $pkg_name =~ s/\.pm$//;
41 if( ( ! -f $pm_path ) || ((stat($asp_filename))[9] > (stat($pm_path))[9] ) )
42 {
43 require Apache2::ASP::ASPPage;
44 Apache2::ASP::ASPPage->init_asp_objects( $context );
45 Apache2::ASP::ASPPage->new( virtual_path => $ENV{SCRIPT_NAME} );
46 }# end if()
47
48 # Now load and execute the compiled ASP:
49 # eval {
50 delete($INC{$pkg_path});
51 require $pkg_path;
52 my $page = $pkg_name->new( virtual_path => $ENV{SCRIPT_NAME} );
53 $page->run( $context, $args );
54 return $context->response->Status == 200 ? 0 : $context->response->Status;
55 # };
56 if( $@ )
57 {
58 $context->response->Status( 500 );
59 confess $@;
60 }# end if()
61 }
62 else
63 {
64 return $context->response->Status( 404 );
65 }# end if()
66 }# end run()
67  
68 1;# return true:
69  
70 =pod
71  
72 =head1 NAME
73  
74 Apache2::ASP::ASPHandler - handler for all *.asp requests
75  
76 =head1 SYNOPSIS
77  
78 Internal use only.
79  
80 =head1 DESCRIPTION
81  
82 This class is the L<Apache2::ASP::HTTPHandler> subclass responsible for handling
83 all requests to C<*.asp> scripts.
84
85 =head1 BUGS
86
87 It's possible that some bugs have found their way into this release.
88
89 Use RT L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP> to submit bug reports.
90
91 =head1 HOMEPAGE
92
93 Please visit the Apache2::ASP homepage at L<http://www.devstack.com/> to see examples
94 of Apache2::ASP in action.
95
96 =head1 AUTHOR
97
98 John Drago L<mailto:jdrago_999@yahoo.com>
99
100 =head1 COPYRIGHT AND LICENSE
101
102 Copyright 2007 John Drago, All rights reserved.
103
104 This software is free software. It may be used and distributed under the
105 same terms as Perl itself.
106
107 =cut
108