File Coverage

blib/lib/ASP4/PageLoader.pm
Criterion Covered Total %
statement 39 39 100.0
branch 6 6 100.0
condition 6 9 66.6
subroutine 8 8 100.0
pod 0 3 0.0
total 59 65 90.7


line stmt bran cond sub pod time code
1              
2             package ASP4::PageLoader;
3              
4 8     8   753 use strict;
  8         13  
  8         261  
5 8     8   31 use warnings 'all';
  8         12  
  8         282  
6 8     8   2867 use ASP4::PageParser;
  8         17  
  8         210  
7 8     8   45 use ASP4::ConfigLoader;
  8         19  
  8         164  
8 8     8   4188 use File::stat;
  8         48152  
  8         38  
9             my %FileTimes = ( );
10              
11              
12             sub discover
13             {
14 6191     6191 0 8294 my ($class, %args) = @_;
15            
16 6191         13300 my $web = ASP4::ConfigLoader->load()->web;
17 6191         17815 my $filename = $web->www_root . $args{script_name};
18            
19             # Expand /folder/ to /folder/index.asp
20 6191 100       68241 if( -d $filename )
21             {
22 4         16 $filename =~ s{/$}{};
23 4         8 $args{script_name} .= "/index.asp";
24 4         8 $filename .= "/index.asp";
25             }# end if()
26 6191         29030 (my $package = $args{script_name}) =~ s/[^a-z0-9]/_/ig;
27 6191         20707 $package = $web->application_name . '::' . $package;
28            
29 6191         18745 (my $compiled_as = "$package.pm") =~ s/::/\//g;
30            
31             return {
32             script_name => $args{script_name},
33 6191         18773 'package' => $package,
34             filename => $filename,
35             compiled_as => $compiled_as,
36             saved_to => $web->page_cache_root . "/$compiled_as",
37             };
38             }# end discover()
39              
40              
41             sub load
42             {
43 3044     3044 0 4657 my ($class, %args) = @_;
44            
45 3044         4784 my $info = $class->discover( script_name => $args{script_name} );
46 3044 100       6035 if( $class->needs_recompile( $info->{saved_to}, $info->{filename} ) )
47             {
48 14         172 my $page = ASP4::PageParser->new( script_name => $info->{script_name} )->parse();
49 14         86 $FileTimes{ $info->{filename} } = stat($info->{filename})->mtime;
50 14         3179 return $page;
51             }# end if()
52              
53 3030         284258 my $config = ASP4::ConfigLoader->load();
54 3030         6750 $config->load_class( $info->{package} );
55 3030   66     7509 $FileTimes{ $info->{filename} } ||= stat($info->{filename})->mtime;
56 3030         11437 return $info->{package}->new();
57             }# end load()
58              
59              
60             sub needs_recompile
61             {
62 3044     3044 0 3259 my ($class, $compiled_as, $filename) = @_;
63            
64 3044 100 66     36452 return 1 unless $compiled_as && -f $compiled_as;
65 3030   66     5508 return stat($filename)->mtime > ( $FileTimes{ $filename } || stat($compiled_as)->mtime );
66             }# end needs_recompile()
67              
68             1;# return true:
69