| 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
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 40 | ▶ | if( $uri =~ m/^\/handlers\// ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2009 | ▶ | if( stat($filepath)->mtime > ($FileTimes{ "$ENV{DOCUMENT_ROOT}:$filepath" } || 0) ) | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$FileTimes{"$ENV{'DOCUMENT_ROOT'}:$filepath"} || 0
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"}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 95 | 3132 | ▶ | return unless -f $info->{saved_to}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 3116 | ▶ | $FileTimes{ "$ENV{DOCUMENT_ROOT}:$info->{filename}" } ||= 0; | ||||||||||||||||||
|
Condition100%2/2
$FileTimes{qq[$ENV{"DOCUMENT_ROOT"}:$info->{"filename"}]} ||= 0
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"}]}
| |||||||||||||||||||||
| 97 | 3116 | ▶ | if( stat($info->{filename})->mtime > $FileTimes{ "$ENV{DOCUMENT_ROOT}:$info->{filename}" } ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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 | |||||||||||||||||||||