UWSGI/Server.pm

filter: Statementstmt 89.7% 79 / 88 Branchbran 55.5% 10 / 18 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 88.4% 23 / 26 Podpod 100% 8 / 8 totaltotal 79.6% 121 / 152 CC 13 SCAR 11.8
CC
13
Cov
79%
on_listen_start
8.3
bus
6.0
listening
5.8
CRAP 3.3
« UWSGI/Server/Connection.pm ↑ Summary UWSGI.pm »
1 package Net::Async::UWSGI::Server;
2 3 $Net::Async::UWSGI::Server::VERSION = '0.006';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use parent qw(IO::Async::Notifier);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Net::Async::UWSGI::Server - server implementation for UWSGI
11  
12 =head1 VERSION
13  
14 version 0.006
15  
16 =head1 SYNOPSIS
17  
18 =head1 DESCRIPTION
19  
20 =cut
21  
22 3 ▶use curry;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use curry::weak;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 ▶use IO::Async::Listener;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 3 ▶use Mixin::Event::Dispatch::Bus;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use Net::Async::UWSGI::Server::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 3 ▶use Protocol::UWSGI qw(:server);
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 =head1 METHODS
41  
42 =cut
43  
44 =head2 path
45  
46 =cut
47  
48 5 ▶sub path { shift->{path} }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
49  
50 =head2 backlog
51  
52 =cut
53  
54 1 ▶sub backlog { shift->{backlog} }
Subroutine backlog: called CC=1 SCAR=0.0
Pod documented
55  
56 =head2 mode
57  
58 =cut
59  
60 1 ▶sub mode { shift->{mode} }
Subroutine mode: called CC=1 SCAR=0.0
Pod documented
61  
62 =head2 configure
63  
64 =cut
65  
66 2 ▶sub configure {
Subroutine configure: called CC=3 SCAR=11.0
Pod documented
67 2 my ($self, %args) = @_;
68 2 for(qw(path backlog mode on_request)) {
69 8 ▶ $self->{$_} = delete $args{$_} if exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$_} 2 6 8
70 }
71 2 $self->SUPER::configure(%args);
72 }
73  
74 =head2 _add_to_loop
75  
76 =cut
77  
78 2 ▶sub _add_to_loop {
Subroutine _add_to_loop: called CC=1 SCAR=0.0
79 2 my ($self, $loop) = @_;
80 2 delete $self->{listening};
81 2 $self->listening;
82 ()
83 1 }
84  
85 =head2 listening
86  
87 =cut
88  
89 2 ▶sub listening {
Subroutine listening: called CC=5 SCAR=17.6
Pod documented
90 2 my ($self) = @_;
91 2 ▶ return $self->{listening} if exists $self->{listening};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"listening"} 0 2 2
92  
93 2 ▶ defined(my $path = $self->path) or die "No path provided";
Branch: 1 branch
BranchTrueFalseTotal
defined(my $path = $self->path) or die "No path provided" 1 1 2
94 1 ▶ unlink $path or die "Unable to remove existing $path socket - $!" if -S $path;
Branch: 1 branch
BranchTrueFalseTotal
if -S $path 0 1 1
Condition20%1/5
-S $path && (unlink($path) || die("Unable to remove existing $path socket - $!"))
!ll&&!rl&&r
100
unlink $path or die "Unable to remove existing $path socket - $!"
l!l
00
MC/DC0%0/2
-S $path && (unlink($path) || die("Unable to remove existing $path socket - $!"))
-S $path unlink $path
Truth table33%1/3
A && B
A= -S $pathB= unlink $path
ABresult
0X0
100
111
95  
96 1 my $f = $self->loop->new_future->set_label('listener startup');
97 1 $self->{listening} = $f;
98 1 my $listener = IO::Async::Listener->new(
99 on_accept => $self->curry::incoming_socket,
100 );
101  
102 1 $self->add_child($listener);
103 $listener->listen(
104 addr => {
105 family => 'unix',
106 socktype => 'stream',
107 path => $self->path,
108 },
109  
110 on_listen => $self->curry::on_listen_start($f),
111 # on_stream => $self->curry::incoming_stream,
112  
113 0 ▶ on_listen_error => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 $f->fail(listen => "Cannot listen - $_[1]\n");
115 },
116 1 );
117 1 $f
118 }
119  
120 =head2 on_listen_start
121  
122 =cut
123  
124 1 ▶sub on_listen_start {
Subroutine on_listen_start: called CC=6 SCAR=21.2
Pod documented
125 1 my ($self, $f, $listener) = @_;
126  
127 1 my $sock = $listener->read_handle;
128  
129 # Make sure the socket is accessible
130 1 ▶ if(my $mode = $self->mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mode = $self->mode) 1 0 1
131 # Allow octal-as-string
132 1 ▶ $mode = oct $mode if substr($mode, 0, 1) eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if substr($mode, 0, 1) eq 0 1 0 1
133 1 $self->debug_printf("chmod %s to %04o", $self->path, $mode);
134 1 ▶ chmod $mode, $self->path or $f->fail(listen => 'unable to chmod socket - ' . $!);
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode, $self->path or $f->fail("listen", 'unable to chmod socket - ' . $!) 1 0 1
135 }
136  
137 # Support custom backlog (default 1 is usually too low)
138 1 ▶ if(my $backlog = $self->backlog) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $backlog = $self->backlog) 0 1 1
139 0 $self->debug_printf("Set listen queue on %s to %d", $self->path, $backlog);
140 0 ▶ $sock->listen($backlog) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$sock->listen($backlog) or die $! 0 0 0
141 }
142  
143 1 $f->done($listener);
144 }
145  
146 =head2 incoming_socket
147  
148 Called when we have an incoming socket. Usually indicates a new request.
149  
150 =cut
151  
152 0 ▶sub incoming_socket {
Subroutine incoming_socket: not called CC=1 SCAR=6.9
Pod documented
153 0 my ($self, $listener, $socket) = @_;
154 0 $self->debug_printf("Incoming socket - %s, total now ", $socket, 0+$self->children);
155  
156 0 $socket->blocking(0);
157 my $stream = Net::Async::UWSGI::Server::Connection->new(
158 handle => $socket,
159 bus => $self->bus,
160 on_request => $self->{on_request},
161 0 autoflush => 1,
162 );
163 0 $self->add_child($stream);
164 }
165  
166 =head2 bus
167  
168 The event bus. See L<Mixin::Event::Dispatch::Bus>.
169  
170 =cut
171  
172 0 ▶sub bus { shift->{bus} ||= Mixin::Event::Dispatch::Bus->new }
Subroutine bus: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
+(shift())->{"bus"} ||= "Mixin::Event::Dispatch::Bus"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
+(shift())->{"bus"} ||= "Mixin::Event::Dispatch::Bus"->new
+(shift())->{"bus"} "Mixin::Event::Dispatch::Bus"->new
Truth table0%0/3
A ||= B
A= +(shift())->{"bus"}B= "Mixin::Event::Dispatch::Bus"->new
ABresult
1X1
011
000
173  
174 3 1;
175  
176 __END__
« UWSGI/Server/Connection.pm ↑ Summary UWSGI.pm »