File Coverage

blib/lib/Apache/ASP/Load.pm
Criterion Covered Total %
statement 49 81 60.4
branch 10 36 27.7
condition 8 19 42.1
subroutine 10 11 90.9
pod 0 4 0.0
total 77 151 50.9


line stmt bran cond sub pod time code
1             package Apache::ASP::Load;
2              
3 1     1   8 use Apache::ASP;
  1         3  
  1         33  
4 1     1   17 use Apache::ASP::CGI::Table;
  1         2  
  1         34  
5              
6 1     1   9 use strict;
  1         2  
  1         52  
7 1     1   5 no strict qw(refs);
  1         20  
  1         37  
8 1     1   5 use vars qw(@Days @Months $AUTOLOAD $LOADED $COUNT);
  1         2  
  1         1567  
9             @Days = qw(Sun Mon Tue Wed Thu Fri Sat);
10             @Months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
11              
12             # we need a different class from Apache::ASP::CGI because we don't
13             # want to force use of CGI & Class::Struct when loading ASP in Apache
14             # also a nasty bug doesn't allow us to eval require's or use's, we
15             # get a can't start_mutex
16              
17             sub new {
18 2     2 0 6 my($file) = @_;
19 2         32 bless {
20             current_callback => 'PerlHandler',
21             filename => $file,
22             remote_ip => '127.0.0.1',
23             user => undef,
24             method => 'GET',
25             NoState => 1,
26             headers_in => Apache::ASP::CGI::Table->new,
27             headers_out => Apache::ASP::CGI::Table->new,
28             dir_config => Apache::ASP::CGI::Table->new,
29             subprocess_env => Apache::ASP::CGI::Table->new,
30             };
31             }
32              
33             sub AUTOLOAD {
34 52     52   276 $AUTOLOAD =~ s/^(.*)::([^:]*)$/$2/;
35 52         335 shift->{$AUTOLOAD};
36             }
37              
38             sub log_error {
39 0     0 0 0 shift;
40 0         0 my @times = localtime;
41 0         0 printf STDERR ('[%s %s %02d %02d:%02d:%02d %d] [error] %s'."\n",
42             $Days[$times[6]],
43             $Months[$times[4]],
44             $times[3],
45             $times[2],
46             $times[1],
47             $times[0],
48             $times[5] + 1900,
49             join('', @_),
50             );
51             }
52              
53 2     2 0 6 sub connection { shift; }
54              
55             sub Run {
56 2 50 33 2 0 140 shift if(ref $_[0] or $_[0] eq 'Apache::ASP');
57              
58 2         15 local $SIG{__WARN__} = \&Apache::ASP::Warn;
59 2         10 my($file, $match, %args) = @_;
60 2 50       59 unless(-e $file) {
61 0         0 warn("$file does not exist for loading");
62 0         0 return;
63             }
64 2   50     12 $match ||= '.*'; # compile all by default
65              
66             # recurse down directories and compile the scripts
67 2 50 33     32 if(-d $file && ! -l $file) {
68 0         0 $file =~ s|/$||;
69 0 0       0 opendir(DIR, $file) || die("can't open $file for reading: $!");
70 0         0 my @files = readdir(DIR);
71 0         0 close DIR;
72 0 0       0 unless(@files) {
73 0         0 Apache::ASP::Load->log_error("[asp] $$ [WARN] can't read files in $file");
74 0         0 return;
75             }
76              
77 0         0 my $top;
78 0 0       0 if(! defined $LOADED) {
79 0         0 $top = 1;
80             }
81 0 0       0 defined $LOADED or (local $LOADED = 0);
82 0 0       0 defined $COUNT or (local $COUNT = 0);
83            
84 0         0 for(@files) {
85 0         0 chomp;
86 0 0       0 next if /^\.\.?$/;
87 0         0 &Run("$file/$_", $match, %args);
88             }
89 0 0       0 if($top) {
90 0         0 Apache::ASP::Load->log_error("[asp] $$ (re)compiled $LOADED scripts of $COUNT loaded for $file");
91             }
92 0         0 return;
93             }
94              
95             # now the real work
96 2 50       26 unless($file =~ /$match/) {
97 0 0 0     0 if($args{Debug} and $args{Debug} < 0) {
98 0         0 Apache::ASP::Load->log_error("skipping compile of $file no match $match");
99             }
100              
101 0         0 return;
102             }
103              
104 2 50       14 unless($file =~ /$match/) {
105 0 0       0 if($args{Debug} < 0) {
106 0         0 warn("skipping compile of $file no match $match");
107             }
108 0         0 return;
109             }
110              
111 2         6 my $r = Apache::ASP::Load::new($file);
112 2         5 for my $key (
  2         12  
113             qw( Debug StatINC StatINCMatch ),
114             @{Apache::ASP->CompileChecksumKeys}
115             )
116             {
117 28         112 $r->dir_config->set($key, $args{$key});
118             }
119 2         10 $r->dir_config->set('NoState', 1);
120              
121             # RegisterIncludes created for precompilation, on by default here
122 2         9 $r->dir_config->set('RegisterIncludes', 1);
123 2 50       7 if ((defined $args{'RegisterIncludes'})) {
124 0         0 $r->dir_config->set('RegisterIncludes', $args{'RegisterIncludes'});
125             }
126              
127 2         4 eval {
128 2         4 $COUNT++;
129 2         11 my $asp = Apache::ASP->new($r);
130              
131             # if StatINC* is configured, run on first script
132 2 50 33     15 if(($COUNT == 1) && ($asp->config('StatINC') || $asp->config('StatINCMatch'))) {
      66        
133 0         0 $asp->StatINC;
134             }
135              
136 2   100     13 my $rv = $asp->CompileInclude($asp->{'basename'})
137             || die($@);
138              
139 1 50       5 if($args{'Execute'}) {
140 1         4 local $^W = 0;
141 1     1   7 local *Apache::ASP::Response::Flush = sub {};
  1         5  
142 1         6 $asp->Run;
143             }
144 1         7 $asp->DESTROY;
145 1         4 $LOADED++;
146             };
147 2 100       14 $@ && warn($@);
148              
149 2         51 return $LOADED;
150             }
151              
152             1;