blib/lib/WebDyne/Request/PSGI/Static.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 83.3% 5 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 82.8% 58 / 70 CC 6 SCAR 12.5
CC
6
Cov
88%
run
6.4
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« blib/lib/WebDyne/Cache.pm ↑ Summary blib/lib/WebDyne/Handler.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Request::PSGI::Static;
14  
15  
16 # Compiler Pragma
17 #
18 2 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use vars qw($VERSION $AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 # External modules
23 #
24 2 ▶use HTTP::Status (qw(HTTP_INTERNAL_SERVER_ERROR HTTP_NOT_FOUND HTTP_OK));
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 # Static subrequests use the common request interface and do not need
31 # Plack. Keep standalone tools usable without a PSGI installation.
32 #
33 2 ▶use WebDyne::Request::Fake;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 @ISA=qw(WebDyne::Request::Fake);
35  
36  
37 # Version information
38 #
39 2 $VERSION='3.029';
40  
41  
42 # Debug load
43 #
44 2 0 && debug("Loading %s version $VERSION", __PACKAGE__);
45  
46  
47 # All done. Positive return
48 #
49 2 1;
50  
51  
52 #==================================================================================================
53  
54  
55 6 ▶sub run {
Subroutine run: called CC=6 SCAR=18.5
Pod undocumented
56  
57 6 my $r_child=shift();
58 6 my $r=$r_child->prev();
59 6 my $fn=$r_child->filename();
60 6 0 && debug("in WebDyne::Request::PSGI::Static, r: $r, fn: $fn");
61 6 ▶ if (!-f $fn) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $fn) { } 1 5 6
elsif (my $fh = 'IO::File'->new($fn, 0)) { } 5 0 5
62 1 warn("file '$fn' not found");
63 1 return $r->status(HTTP_NOT_FOUND);
64 }
65 elsif (my $fh=IO::File->new($fn, O_RDONLY)) {
66 5 my $hr=$r->headers_out();
67 5 my $size=(stat($fn))[7];
68 5 $hr->{'Content-Length'}=$size;
69 5 ▶ my $ext=($fn=~/\.(\w+)$/) && $1;
Condition33%1/3
$fn =~ /\.(\w+)$/ && $1
!ll&&!rl&&r
005
MC/DC0%0/2
$fn =~ /\.(\w+)$/ && $1
$fn =~ /\.(\w+)$/ $1
Truth table33%1/3
A && B
A= $fn =~ /\.(\w+)$/B= $1
ABresult
0X0
100
111
70 5 ▶ $hr->{'Content-Type'}=$WEBDYNE_MIME_TYPE_HR->{$ext} || $WEBDYNE_CONTENT_TYPE_TEXT;
Condition33%1/3
$WebDyne::Request::PSGI::Static::WEBDYNE_MIME_TYPE_HR->{$ext} || $WebDyne::Request::PSGI::Static::WEBDYNE_CONTENT_TYPE_TEXT
l!l&&r!l&&!r
500
MC/DC0%0/2
$WebDyne::Request::PSGI::Static::WEBDYNE_MIME_TYPE_HR->{$ext} || $WebDyne::Request::PSGI::Static::WEBDYNE_CONTENT_TYPE_TEXT
$WebDyne::Request::PSGI::Static::WEBDYNE_MIME_TYPE_HR->{$ext} $WebDyne::Request::PSGI::Static::WEBDYNE_CONTENT_TYPE_TEXT
Truth table33%1/3
A || B
A= $WebDyne::Request::PSGI::Static::WEBDYNE_MIME_TYPE_HR->{$ext}B= $WebDyne::Request::PSGI::Static::WEBDYNE_CONTENT_TYPE_TEXT
ABresult
1X1
011
000
71 5 $r->send_http_header();
72 5 my $buf;
73 5 ▶ while (read($fh, $buf, 8192)) {$r->print($buf)}
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $buf, 8192) 6 5 11
74 5 $fh->close();
75 5 return HTTP_OK
76 }
77 else {
78 0 warn("unable to open file '$fn', $!");
79 0 return $r->status(HTTP_INTERNAL_SERVER_ERROR);
80 }
81  
82 }
83 __END__
« blib/lib/WebDyne/Cache.pm ↑ Summary blib/lib/WebDyne/Handler.pm »