blib/lib/ASP4/HandlerResolver.pm

filter: Statementstmt 97.2% 71 / 73 Branchbran 83.3% 20 / 24 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 91.5% 108 / 118 CC 15 SCAR 16.5
CC
15
Cov
94%
check_reload
9.0
resolve_request_handler
6.1
_forget_package
2.0
CRAP 5.2
« blib/lib/ASP4/Response.pm ↑ Summary blib/lib/ASP4/SessionStateManager/Memcached.pm »
1  
2 package
3 ASP4::HandlerResolver;
4  
5 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use ASP4::PageLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 my %HandlerCache = ( );
10 14 my %FileTimes = ( );
11  
12  
13 sub new
14 5145 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
15 5145 my ($class, %args) = @_;
16
17 5145 return bless \%args, $class;
18 }# end new()
19  
20  
21 2025 ▶sub context { ASP4::HTTPContext->current }
Subroutine context: called CC=1 SCAR=0.0
Pod undocumented
22  
23  
24 sub resolve_request_handler
25 5145 ▶{
Subroutine resolve_request_handler: called CC=6 SCAR=18.1
Pod undocumented
26 5145 my ($s, $uri) = @_;
27
28 5145 ($uri) = split /\?/, $uri;
29 5145 $s->check_reload( $uri );
30 5145 ▶ return $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} if $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"};
Branch: 1 branch
BranchTrueFalseTotal
if $HandlerCache{qq[$ENV{"DOCUMENT_ROOT"}:$uri]} 5105 40 5145
31
32 40 ▶ if( $uri =~ m/^\/handlers\// )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ m[^/handlers/]) { } 8 32 40
33 {
34 8 (my $handler = $uri) =~ s/^\/handlers\///;
35 8 $handler =~ s/[^a-z0-9_]/::/gi;
36 8 (my $path = "$handler.pm") =~ s/::/\//g;
37 8 my $filepath = $s->context->config->web->handler_root . "/$path";
38
39 8 ▶ if( -f $filepath )
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filepath) { } 8 0 8
40 {
41 8 $s->context->config->load_class( $handler );
42 8 return $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} = $handler;
43 }
44 else
45 {
46 0 return;
47 }# end if()
48 }
49 else
50 {
51 32 my $info = ASP4::PageLoader->discover( script_name => $uri );
52 32 ▶ if( $info->{is_static} )
Branch: 2 branches
BranchTrueFalseTotal
if ($info->{'is_static'}) { } 4 28 32
elsif (-f $info->{'filename'}) { } 28 0 28
53 {
54 4 return $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} = 'ASP4::StaticHandler';
55 }
56 elsif( -f $info->{filename} )
57 {
58 28 my $page = ASP4::PageLoader->load( script_name => $uri );
59 28 return $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} = $page->package;
60 }
61 else
62 {
63 0 return;
64 }# end if()
65 }# end if()
66 }# end resolve_request_handler()
67  
68  
69 sub check_reload
70 5145 ▶{
Subroutine check_reload: called CC=9 SCAR=22.0
Pod undocumented
71 5145 my ($s, $uri) = @_;
72  
73 5145 ▶ if( $uri =~ m/^\/handlers\// )
Branch: 1 branch
BranchTrueFalseTotal
if ($uri =~ m[^/handlers/]) { } 2009 3136 5145
74 {
75 2009 (my $handler = $uri) =~ s/^\/handlers\///;
76 2009 $handler =~ s/[^a-z0-9_]/::/gi;
77 2009 (my $path = "$handler.pm") =~ s/::/\//g;
78 2009 my $filepath = $s->context->config->web->handler_root . "/$path";
79 2009 (my $inc_entry = "$handler.pm") =~ s/::/\//g;
80 2009 ▶ return unless -f $filepath;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filepath 0 2009 2009
81
82 2009 ▶ if( stat($filepath)->mtime > ($FileTimes{ "$ENV{DOCUMENT_ROOT}:$filepath" } || 0) )
Branch: 1 branch
BranchTrueFalseTotal
if (&ASP4::HandlerResolver::stat($filepath)->mtime > ($FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$filepath]} || 0)) 8 2001 2009
Condition100%2/2
$FileTimes{"$ENV{'DOCUMENT_ROOT'}:$filepath"} || 0
l!l
20018
MC/DC100%1/1
$FileTimes{"$ENV{'DOCUMENT_ROOT'}:$filepath"} || 0
$FileTimes{"$ENV{'DOCUMENT_ROOT'}:$filepath"}
Truth table100%2/2
A
A= $FileTimes{"$ENV{'DOCUMENT_ROOT'}:$filepath"}
Aresult
11
00
83 {
84 8 $FileTimes{ "$ENV{DOCUMENT_ROOT}:$filepath" } = stat($filepath)->mtime;
85 8 $s->_forget_package(
86 $inc_entry, $handler
87 );
88 8 delete( $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} );
89 }# end if()
90 }
91 else
92 {
93 3136 my $info = ASP4::PageLoader->discover( script_name => $uri );
94 3136 ▶ return if $info->{is_static};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"is_static"} 4 3132 3136
95 3132 ▶ return unless -f $info->{saved_to};
Branch: 1 branch
BranchTrueFalseTotal
unless -f $info->{"saved_to"} 16 3116 3132
96 3116 ▶ $FileTimes{ "$ENV{DOCUMENT_ROOT}:$info->{filename}" } ||= 0;
Condition100%2/2
$FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]} ||= 0
l!l
310412
MC/DC100%1/1
$FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]} ||= 0
$FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]}
Truth table100%2/2
A
A= $FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]}
Aresult
11
00
97 3116 ▶ if( stat($info->{filename})->mtime > $FileTimes{ "$ENV{DOCUMENT_ROOT}:$info->{filename}" } )
Branch: 1 branch
BranchTrueFalseTotal
if (&ASP4::HandlerResolver::stat($info->{"filename"})->mtime > $FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]}) 12 3104 3116
98 {
99 12 $FileTimes{ "$ENV{DOCUMENT_ROOT}:$info->{filename}" } = stat($info->{filename})->mtime;
100 $s->_forget_package(
101 $info->{compiled_as}, $info->{package}
102 12 );
103 12 delete( $HandlerCache{"$ENV{DOCUMENT_ROOT}:$uri"} );
104 }# end if()
105 }# end if()
106 }# end check_reload()
107  
108  
109 sub _forget_package
110 3058 ▶{
Subroutine _forget_package: called CC=2 SCAR=6.9
111 3058 my ($s, $inc, $package) = @_;
112
113 # Forcibly forget all about the handler we are going to reload:
114 14 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
115 3058 delete( $INC{ $inc } );
116 3058 ▶ if( *{"$package\::run"} )
Branch: 1 branch
BranchTrueFalseTotal
if (*{"${package}::run";}) 3058 0 3058
117 {
118 14 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 3058 *{"$package\::run"} = undef;
120 3058 *{"$package\::before_run"} = undef;
121 3058 *{"$package\::after_run"} = undef;
122 }# end if()
123 }# end _forget_package()
124  
125 14 1;# return true:
126  
« blib/lib/ASP4/Response.pm ↑ Summary blib/lib/ASP4/SessionStateManager/Memcached.pm »