lib/WebDyne/Request/PSGI/Static.pm

filter: Statementstmt 91.1% 41 / 45 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 78.5% 55 / 70 CC 6 SCAR 13.4
CC
6
Cov
82%
run
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« bin/wddump ↑ Summary blib/lib/WebDyne/Cache.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 debug("Loading %s version $VERSION", __PACKAGE__);
45  
46  
47 # All done. Positive return
48 #
49 2 1;
50  
51  
52 #==================================================================================================
53  
54  
55 2 ▶sub run {
Subroutine run: called CC=6 SCAR=19.6
Pod undocumented
56  
57 2 my $r_child=shift();
58 2 my $r=$r_child->prev();
59 2 my $fn=$r_child->filename();
60 2 debug("in WebDyne::Request::PSGI::Static, r: $r, fn: $fn");
61 2 ▶ if (!-f $fn) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $fn) { } 0 2 2
elsif (my $fh = 'IO::File'->new($fn, 0)) { } 2 0 2
62 0 warn("file '$fn' not found");
63 0 return $r->status(HTTP_NOT_FOUND);
64 }
65 elsif (my $fh=IO::File->new($fn, O_RDONLY)) {
66 2 my $hr=$r->headers_out();
67 2 my $size=(stat($fn))[7];
68 2 $hr->{'Content-Length'}=$size;
69 2 ▶ my $ext=($fn=~/\.(\w+)$/) && $1;
Condition33%1/3
$fn =~ /\.(\w+)$/ && $1
!ll&&!rl&&r
002
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 2 ▶ $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
200
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 2 $r->send_http_header();
72 2 my $buf;
73 2 ▶ while (read($fh, $buf, 8192)) {$r->print($buf)}
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, $buf, 8192) 2 2 4
74 2 $fh->close();
75 2 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__
« bin/wddump ↑ Summary blib/lib/WebDyne/Cache.pm »