blib/lib/PAGI/Server/Runner.pm

filter: Statementstmt 76.7% 211 / 275 Branchbran 53.4% 93 / 174 Conditioncond 66.6% 42 / 63 MC/DCmcdc 40.5% 15 / 37 Subroutinesub 92.8% 26 / 28 Podpod 100% 7 / 7 totaltotal 67.4% 394 / 584 CC 117 SCAR 31.7
CC
117
Cov
68%
_daemonize
110.0
_drop_privileges
51.1
parse_options
25.2
CRAP 23.7
« blib/lib/PAGI/Server/Connection.pm ↑ Summary blib/lib/PAGI/Server/Protocol/HTTP1.pm »
1 package PAGI::Server::Runner;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 16 our $VERSION = '0.002011';
7  
8 16 ▶use Getopt::Long qw(GetOptionsFromArray :config pass_through no_auto_abbrev no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use POSIX qw(setsid);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use FindBin ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 16 ▶use PAGI::Server::AppNormalizer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 PAGI::Server::Runner - PAGI application loader and server runner
19  
20 =head1 SYNOPSIS
21  
22 # Command line usage via pagi-server
23 pagi-server PAGI::App::Directory root=/var/www
24 pagi-server ./app.pl -p 8080
25 pagi-server # serves current directory
26  
27 # With environment modes
28 pagi-server -E development app.pl # enable Lint middleware
29 pagi-server -E production app.pl # no auto-middleware
30 PAGI_ENV=production pagi-server app.pl
31  
32 # Programmatic usage
33 use PAGI::Server::Runner;
34  
35 PAGI::Server::Runner->run(@ARGV);
36  
37 =head1 DESCRIPTION
38  
39 PAGI::Server::Runner is a loader and runner for PAGI applications, similar to
40 L<Plack::Runner> for PSGI. It handles CLI argument parsing, app loading
41 (from files or modules), environment modes, and server orchestration.
42  
43 The runner is designed to be server-agnostic. Common options like host,
44 port, and daemonize are handled by the runner, while server-specific
45 options are passed through to the server backend.
46  
47 =head1 ENVIRONMENT MODES
48  
49 PAGI::Server::Runner supports environment modes similar to Plack's C<-E> flag:
50  
51 =over 4
52  
53 =item development
54  
55 Auto-enables L<PAGI::Middleware::Lint> with strict mode to catch
56 specification violations early (when PAGI-Tools is installed). This is
57 the default when running interactively (TTY detected).
58  
59 =item production
60  
61 No middleware is auto-enabled. This is the default when running
62 non-interactively (no TTY, e.g., systemd, docker, cron).
63  
64 =item none
65  
66 Explicit opt-out of all auto-middleware, regardless of TTY detection.
67  
68 =back
69  
70 Mode is determined by (in order of precedence):
71  
72 1. -E / --env command line flag
73 2. PAGI_ENV environment variable
74 3. Auto-detection: TTY = development, no TTY = production
75  
76 After determining the mode, the runner sets C<PAGI_ENV> to the resolved
77 value. This allows your application to check C<$ENV{PAGI_ENV}> to know
78 what mode it's running in, similar to Plack's C<PLACK_ENV>.
79  
80 Use C<--no-default-middleware> to disable auto-middleware while keeping
81 the mode for other purposes.
82  
83 =head1 APP LOADING
84  
85 The runner supports three ways to specify an application:
86  
87 =head2 Module Name
88  
89 If the app specifier contains C<::>, it's treated as a module name:
90  
91 pagi-server PAGI::App::Directory root=/var/www show_hidden=1
92  
93 The module is loaded and C<new> is called with the provided key=value
94 arguments. The constructed value may be a native PAGI coderef or an
95 instantiated application-provider object. A provider is normalized by calling
96 C<to_app> exactly once; C<to_app> is never invoked as a class method.
97  
98 =head2 File Path
99  
100 If the app specifier contains C</> or ends with C<.pl> or C<.psgi>,
101 it's treated as a file path:
102  
103 pagi-server ./app.pl
104 pagi-server /path/to/myapp.psgi
105  
106 The file is loaded via C<do> and must return either a native PAGI coderef or an
107 instantiated application-provider object. A provider is normalized through
108 C<to_app> exactly once before the server is constructed.
109  
110 For compatibility with Plack's C<plackup>, the runner localizes C<$0> to the
111 app file before loading it. This ensures C<FindBin::Bin> resolves to the app
112 file directory inside the app. If C<FindBin> was already loaded, the runner
113 also calls C<FindBin::again()> to refresh its cached path.
114  
115 =head2 Default
116  
117 If no app is specified, defaults to serving the current directory:
118  
119 pagi-server # same as: PAGI::App::Directory root=.
120  
121 =head1 METHODS
122  
123 =head2 run
124  
125 PAGI::Server::Runner->run(@ARGV);
126  
127 Class method that creates a runner, parses options, loads the app,
128 and runs the server. This is the main entry point for CLI usage.
129  
130 =head2 new
131  
132 my $runner = PAGI::Server::Runner->new(%options);
133  
134 Creates a new runner instance. Most users should use C<run()> instead.
135  
136 =cut
137  
138 sub new {
139 72 ▶ my ($class, %args) = @_;
Subroutine new: called CC=7 SCAR=20.1
Pod documented
140  
141 return bless {
142 # Runner options (common to all servers)
143 host => $args{host},
144 port => $args{port},
145 server => $args{server},
146 env => $args{env},
147 quiet => $args{quiet} // 0,
148 loop => $args{loop},
149 access_log => $args{access_log},
150 no_access_log => $args{no_access_log} // 0,
151 daemonize => $args{daemonize} // 0,
152 pid_file => $args{pid_file},
153 user => $args{user},
154 group => $args{group},
155 libs => $args{libs} // [],
156 modules => $args{modules} // [],
157 eval => $args{eval},
158 default_middleware => $args{default_middleware},
159  
160 # Internal state
161 app => undef,
162 app_spec => undef,
163 app_args => {},
164 server_options => $args{server_options} // {},
165 72 ▶ argv => [],
Condition75%9/12
$args{"quiet"} // 0
l!l
1953
$args{"no_access_log"} // 0
l!l
072
$args{"daemonize"} // 0
l!l
171
$args{"libs"} // []
l!l
072
$args{"modules"} // []
l!l
072
$args{"server_options"} // {}
l!l
567
MC/DC100%1/1
$args{"quiet"} // 0
$args{"quiet"}
MC/DC0%0/1
$args{"no_access_log"} // 0
$args{"no_access_log"}
MC/DC100%1/1
$args{"daemonize"} // 0
$args{"daemonize"}
MC/DC0%0/1
$args{"libs"} // []
$args{"libs"}
MC/DC0%0/1
$args{"modules"} // []
$args{"modules"}
MC/DC100%1/1
$args{"server_options"} // {}
$args{"server_options"}
Truth table100%2/2
A
A= $args{"quiet"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"no_access_log"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"daemonize"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"libs"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"modules"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"server_options"}
Aresult
11
00
166 }, $class;
167 }
168  
169 =head2 parse_options
170  
171 $runner->parse_options(@args);
172  
173 Parses CLI options from the argument list. Common options are stored
174 in the runner object. Server-specific options are passed separately
175 via the C<server_options> hashref (see L</load_server>).
176  
177 =head3 Common Options (handled by Runner)
178  
179 -a, --app FILE Load app from file (legacy option)
180 -e CODE Inline app code (like perl -e)
181 -M MODULE Load MODULE before -e (repeatable, like perl -M)
182 -o, --host HOST Bind address (default: 127.0.0.1)
183 -p, --port PORT Bind port (default: 5000)
184 -s, --server CLASS Server class (default: PAGI::Server)
185 -E, --env MODE Environment mode (development, production, none)
186 -I, --lib PATH Add PATH to @INC (repeatable)
187 -l, --loop BACKEND Event loop backend (EV, Epoll, UV, Poll)
188 -D, --daemonize Run as background daemon
189 --access-log FILE Access log file (default: STDERR)
190 --no-access-log Disable access logging
191 --pid FILE Write PID to file
192 --user USER Run as specified user (after binding)
193 --group GROUP Run as specified group (after binding)
194 -q, --quiet Suppress startup messages
195 --default-middleware Toggle mode middleware (default: on)
196 -v, --version Show version info
197 --help Show help
198  
199 Example with C<-e> and C<-M>:
200  
201 pagi-server -MPAGI::App::File -e 'PAGI::App::File->new(root => ".")'
202  
203 =head3 Server-Specific Options
204  
205 Server-specific options should be parsed by the server's CLI wrapper
206 (e.g., C<bin/pagi-server>) and passed to Runner via the C<server_options>
207 hashref parameter. This keeps Runner server-agnostic.
208  
209 See L<PAGI::Server> for available options when using pagi-server.
210  
211 =cut
212  
213 sub parse_options {
214 32 ▶ my ($self, @args) = @_;
Subroutine parse_options: called CC=25 SCAR=32.3
Pod documented
215  
216 # Check for server_options hashref passed from bin/pagi-server
217 32 for my $i (0 .. $#args) {
218 123 ▶ if ($args[$i] eq 'server_options' && ref($args[$i + 1]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[$i] eq "server_options" and ref $args[$i + 1] eq "HASH") 11 112 123
Condition66%2/3
$args[$i] eq "server_options" and ref $args[$i + 1] eq "HASH"
!ll&&!rl&&r
112011
MC/DC50%1/2
$args[$i] eq "server_options" and ref $args[$i + 1] eq "HASH"
$args[$i] eq "server_options" ref $args[$i + 1] eq "HASH"
Truth table66%2/3
A and B
A= $args[$i] eq "server_options"B= ref $args[$i + 1] eq "HASH"
ABresult
0X0
100
111
219 11 $self->{server_options} = $args[$i + 1];
220 11 splice @args, $i, 2;
221 11 last;
222 }
223 }
224  
225 # Pre-process cuddled options like -MModule or -e"code" → -M Module, -e "code"
226 # This matches Plack::Runner behavior for perl-like flags
227 32 ▶ @args = map { /^(-[IMMe])(.+)/ ? ($1, $2) : $_ } @args;
Branch: 1 branch
BranchTrueFalseTotal
/^(-[IMMe])(.+)/ ? : 1 112 113
228  
229 32 my %opts;
230 my @libs;
231 32 my @modules;
232  
233 # Parse runner options, pass through unknown for server
234 GetOptionsFromArray(
235 \@args,
236 # App loading
237 'a|app=s' => \$opts{app},
238 'e=s' => \$opts{eval},
239 'I|lib=s' => \@libs,
240 'M=s' => \@modules,
241  
242 # Network
243 'o|host=s' => \$opts{host},
244 'p|port=i' => \$opts{port},
245  
246 # Server selection (future: pluggable servers)
247 's|server=s' => \$opts{server},
248  
249 # Environment/mode
250 'E|env=s' => \$opts{env},
251  
252 # Event loop
253 'l|loop=s' => \$opts{loop},
254  
255 # Logging
256 'access-log=s' => \$opts{access_log},
257 'no-access-log' => \$opts{no_access_log},
258  
259 # Daemon/process
260 'D|daemonize' => \$opts{daemonize},
261 'pid=s' => \$opts{pid_file},
262 'user=s' => \$opts{user},
263 'group=s' => \$opts{group},
264  
265 # Output
266 'q|quiet' => \$opts{quiet},
267 'default-middleware!' => \$opts{default_middleware},
268  
269 # Help/version
270 'help' => \$opts{help},
271 'v|version' => \$opts{version},
272 32 ▶ ) or die "Error parsing options\n";
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@args, "a|app=s", \$opts{"app"}, "e=s", \$opts{"eval"}, "I|lib=s", \@libs, "M=s", \@modules, "o|host=s", \$opts{"host"}, "p|port=i", \$opts{"port"}, "s|server=s", \$opts{"server"}, "E|env=s", \$opts{"env"}, "l|loop=s", \$opts{"loop"}, "access-log=s", \$opts{"access_log"}, "no-access-log", \$opts{"no_access_log"}, "D|daemonize", \$opts{"daemonize"}, "pid=s", \$opts{"pid_file"}, "user=s", \$opts{"user"}, "group=s", \$opts{"group"}, "q|quiet", \$opts{"quiet"}, "default-middleware!", \$opts{"default_middleware"}, "help", \$opts{"help"}, "v|version", \$opts{"version"}) or die "Error parsing options\n" 0 32 32
273  
274 # Store the selected server class before the version/help early-return
275 # so --version can report the configured server (see _show_version).
276 32 ▶ $self->{server} = $opts{server} if defined $opts{server};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"server"} 6 26 32
277  
278 # Handle help/version flags
279 32 ▶ if ($opts{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"version"}) 1 31 32
280 1 $self->{show_version} = 1;
281 1 return;
282 }
283 31 ▶ if ($opts{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"help"}) 1 30 31
284 1 $self->{show_help} = 1;
285 1 return;
286 }
287  
288 # Apply parsed options
289 30 ▶ $self->{host} = $opts{host} if defined $opts{host};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"host"} 2 28 30
290 30 ▶ $self->{port} = $opts{port} if defined $opts{port};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"port"} 11 19 30
291 30 ▶ $self->{env} = $opts{env} if defined $opts{env};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"env"} 2 28 30
292 30 ▶ $self->{loop} = $opts{loop} if defined $opts{loop};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"loop"} 1 29 30
293 30 ▶ $self->{access_log} = $opts{access_log} if defined $opts{access_log};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"access_log"} 0 30 30
294 30 ▶ $self->{no_access_log} = $opts{no_access_log} if $opts{no_access_log};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"no_access_log"} 0 30 30
295 30 ▶ $self->{daemonize} = $opts{daemonize} if $opts{daemonize};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"daemonize"} 4 26 30
296 30 ▶ $self->{pid_file} = $opts{pid_file} if defined $opts{pid_file};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"pid_file"} 3 27 30
297 30 ▶ $self->{user} = $opts{user} if defined $opts{user};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"user"} 3 27 30
298 30 ▶ $self->{group} = $opts{group} if defined $opts{group};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"group"} 3 27 30
299 30 ▶ $self->{quiet} = $opts{quiet} if $opts{quiet};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"quiet"} 3 27 30
300 $self->{default_middleware} = $opts{default_middleware}
301 30 ▶ if defined $opts{default_middleware};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"default_middleware"} 1 29 30
302  
303 # Add library paths
304 30 ▶ push @{$self->{libs}}, @libs if @libs;
Branch: 1 branch
BranchTrueFalseTotal
if @libs 0 30 30
305  
306 # Store -M modules for loading
307 30 ▶ push @{$self->{modules}}, @modules if @modules;
Branch: 1 branch
BranchTrueFalseTotal
if @modules 2 28 30
308  
309 # Store -e eval code
310 30 ▶ $self->{eval} = $opts{eval} if defined $opts{eval};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"eval"} 6 24 30
311  
312 # Legacy --app flag
313 30 ▶ if (defined $opts{app}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"app"}) 5 25 30
314 5 $self->{app_spec} = $opts{app};
315 }
316  
317 # Remaining args go to argv (app spec and app args)
318 30 push @{$self->{argv}}, @args;
319 }
320  
321 =head2 mode
322  
323 my $mode = $runner->mode;
324  
325 Returns the current environment mode. Determines mode by checking
326 (in order): explicit C<-E> flag, C<PAGI_ENV> environment variable,
327 or auto-detection based on TTY.
328  
329 =cut
330  
331 sub mode {
332 57 ▶ my ($self) = @_;
Subroutine mode: called CC=4 SCAR=13.9
Pod documented
333  
334 57 ▶ return $self->{env} if defined $self->{env};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"env"} 4 53 57
335 53 ▶ return $ENV{PAGI_ENV} if defined $ENV{PAGI_ENV};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"PAGI_ENV"} 37 16 53
336 16 ▶ return -t STDIN ? 'development' : 'production';
Branch: 1 branch
BranchTrueFalseTotal
-t STDIN ? : 0 16 16
337 }
338  
339 =head2 load_app
340  
341 my $app = $runner->load_app;
342  
343 Loads the PAGI application based on the app specifier from command
344 line arguments. Every accepted loading form is normalized to and returns the
345 native PAGI app coderef used by the server.
346  
347 =cut
348  
349 sub load_app {
350 26 ▶ my ($self) = @_;
Subroutine load_app: called CC=14 SCAR=29.8
Pod documented
351  
352 # Add library paths to @INC before loading
353 26 ▶ if (@{$self->{libs}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"libs"};}) 0 26 26
354 0 unshift @INC, @{$self->{libs}};
355 }
356  
357 # Load -M modules before evaluating -e code
358 26 for my $module (@{$self->{modules}}) {
359 # Handle Module=import,args syntax like perl -M
360 0 my ($mod, $imports) = split /=/, $module, 2;
361 0 eval "require $mod";
362 0 ▶ die "Cannot load module $mod: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
363 0 ▶ if (defined $imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $imports) { } 0 0 0
364 0 my @imports = split /,/, $imports;
365 0 $mod->import(@imports);
366 } else {
367 0 $mod->import;
368 }
369 }
370  
371 # Handle -e inline code
372 26 ▶ if (defined $self->{eval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"eval"}) 4 22 26
373 4 my $code = $self->{eval};
374 4 my $app = eval $code;
375 4 ▶ die "Error evaluating -e code: $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
376 4 $app = PAGI::Server::AppNormalizer::normalize_app($app, '-e code');
377 3 $self->{app_spec} = '-e';
378 3 $self->{app} = $app;
379 3 return $app;
380 }
381  
382 # Get app spec from argv if not set via --app
383 22 my @argv = @{$self->{argv}};
384 22 ▶ if (!$self->{app_spec} && @argv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"app_spec"} and @argv) 8 14 22
Condition66%2/3
not $self->{"app_spec"} and @argv
!ll&&!rl&&r
1408
MC/DC50%1/2
not $self->{"app_spec"} and @argv
not $self->{"app_spec"} @argv
Truth table66%2/3
not(A) and B
A= not $self->{"app_spec"}B= @argv
ABresult
0X0
100
111
385 8 my $first = $argv[0];
386 # Check if first arg looks like an app spec (not a key=value)
387 8 ▶ if ($first !~ /=/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($first =~ /=/) 8 0 8
388 8 $self->{app_spec} = shift @argv;
389 8 $self->{argv} = \@argv;
390 }
391 }
392  
393 22 my $app_spec = $self->{app_spec};
394  
395 # Default: serve current directory
396 22 my %app_args;
397 22 ▶ if (!defined $app_spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $app_spec) { } 0 22 22
398 0 $app_spec = 'PAGI::App::Directory';
399 0 %app_args = (root => '.');
400 } else {
401 # Parse constructor args (key=value pairs) from remaining argv
402 22 %app_args = $self->_parse_app_args(@{$self->{argv}});
403 }
404  
405 22 $self->{app_spec} = $app_spec;
406 22 $self->{app_args} = \%app_args;
407  
408 22 my $app;
409 22 ▶ if ($self->_is_module_name($app_spec)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_module_name($app_spec)) { } 1 21 22
elsif ($self->_is_file_path($app_spec)) { } 19 2 21
410 1 $app = $self->_load_module($app_spec, %app_args);
411 }
412 elsif ($self->_is_file_path($app_spec)) {
413 19 $app = $self->_load_file($app_spec);
414 }
415 else {
416 # Ambiguous - try as file first, then module
417 2 ▶ if (-f $app_spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $app_spec) { } 0 2 2
418 0 $app = $self->_load_file($app_spec);
419 }
420 else {
421 2 $app = $self->_load_module($app_spec, %app_args);
422 }
423 }
424  
425 19 $self->{app} = $app;
426 19 return $app;
427 }
428  
429 =head2 prepare_app
430  
431 my $app = $runner->prepare_app;
432  
433 Loads the app and wraps it with mode-appropriate middleware.
434 In development mode (with default_middleware enabled), wraps
435 with L<PAGI::Middleware::Lint> if available (requires PAGI-Tools).
436  
437 =cut
438  
439 sub prepare_app {
440 14 ▶ my ($self) = @_;
Subroutine prepare_app: called CC=7 SCAR=27.5
Pod documented
441  
442 14 my $app = $self->load_app;
443  
444 # Wrap with mode middleware unless disabled
445 14 ▶ my $use_middleware = $self->{default_middleware} // 1;
Condition100%2/2
$self->{"default_middleware"} // 1
l!l
311
MC/DC100%1/1
$self->{"default_middleware"} // 1
$self->{"default_middleware"}
Truth table100%2/2
A
A= $self->{"default_middleware"}
Aresult
11
00
446  
447 14 ▶ if ($use_middleware && $self->mode eq 'development') {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_middleware and $self->mode eq "development") 0 14 14
Condition66%2/3
$use_middleware and $self->mode eq "development"
!ll&&!rl&&r
3110
MC/DC0%0/2
$use_middleware and $self->mode eq "development"
$use_middleware $self->mode eq "development"
Truth table66%2/3
A and B
A= $use_middlewareB= $self->mode eq "development"
ABresult
0X0
100
111
448 0 ▶ if (eval { require PAGI::Middleware::Lint; 1 }) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require PAGI::Middleware::Lint; 1 } }) { } 0 0 0
elsif (not $self->{'quiet'}) { } 0 0 0
449 0 $app = PAGI::Middleware::Lint->new(strict => 1)->wrap($app);
450 warn "PAGI development mode - Lint middleware enabled\n"
451 0 ▶ unless $self->{quiet};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"quiet"} 0 0 0
452 }
453 elsif (!$self->{quiet}) {
454 0 warn "PAGI development mode - install PAGI-Tools for Lint middleware\n";
455 }
456 }
457  
458 14 $self->{app} = $app;
459 14 return $app;
460 }
461  
462 =head2 load_server
463  
464 my $server = $runner->load_server;
465  
466 Constructs the configured server class (C<-s CLASS>, default
467 L<PAGI::Server>) according to this runner's backend convention:
468 C<< $class->new(%options) >> followed by C<< $server->run >>. This is a
469 PAGI::Server::Runner plugin interface, not a construction API required by
470 L<PAGI::Spec::Server>.
471  
472 Creates the server instance with the prepared app and configuration.
473 Parses server-specific options and passes them to the server constructor.
474  
475 =cut
476  
477 sub load_server {
478 20 ▶ my ($self) = @_;
Subroutine load_server: called CC=16 SCAR=31.7
Pod documented
479  
480 20 ▶ my $server_class = $self->{server} // 'PAGI::Server';
Condition100%2/2
$self->{"server"} // "PAGI::Server"
l!l
1010
MC/DC100%1/1
$self->{"server"} // "PAGI::Server"
$self->{"server"}
Truth table100%2/2
A
A= $self->{"server"}
Aresult
11
00
481  
482 # Load server class
483 20 my $server_file = $server_class;
484 20 $server_file =~ s{::}{/}g;
485 20 $server_file .= '.pm';
486  
487 20 eval { require $server_file };
488 20 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 20 20
489 0 die "Cannot load server '$server_class': $@\n";
490 }
491  
492 # Get server-specific options (passed from bin/pagi-server or similar)
493 20 ▶ my %server_opts = %{$self->{server_options} // {}};
Condition50%1/2
$self->{"server_options"} // {}
l!l
200
MC/DC0%0/1
$self->{"server_options"} // {}
$self->{"server_options"}
Truth table50%1/2
A
A= $self->{"server_options"}
Aresult
11
00
494  
495 # Handle access log
496 # Production mode disables logging by default for performance
497 # Use --access-log to explicitly enable in production
498 20 my $access_log;
499 20 my $disable_log = 0;
500  
501 20 ▶ if ($self->{no_access_log}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'no_access_log'}) { } 0 20 20
elsif ($self->{'access_log'}) { } 0 20 20
elsif ($self->mode eq 'production') { } 20 0 20
502 # Explicit --no-access-log
503 0 $disable_log = 1;
504 }
505 elsif ($self->{access_log}) {
506 # Explicit --access-log FILE
507 open $access_log, '>>', $self->{access_log}
508 0 ▶ or die "Cannot open access log $self->{access_log}: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $access_log, ">>", $self->{"access_log"} or die qq[Cannot open access log $self->{"access_log"}: $!\n] 0 0 0
509 }
510 elsif ($self->mode eq 'production') {
511 # Production mode: disable logging by default
512 20 $disable_log = 1;
513 }
514 # else: development mode uses server default (STDERR)
515  
516 # Build server
517 # Omit host/port when socket or listen is provided (mutually exclusive)
518 20 ▶ my $has_socket_or_listen = exists $server_opts{socket} || exists $server_opts{listen};
Condition100%3/3
exists $server_opts{'socket'} || exists $server_opts{'listen'}
l!l&&r!l&&!r
1118
MC/DC100%2/2
exists $server_opts{'socket'} || exists $server_opts{'listen'}
exists $server_opts{'socket'} exists $server_opts{'listen'}
Truth table100%3/3
A || B
A= exists $server_opts{'socket'}B= exists $server_opts{'listen'}
ABresult
1X1
011
000
519 return $server_class->new(
520 app => $self->{app},
521 ($has_socket_or_listen ? () : (
522 host => $self->{host} // '127.0.0.1',
523 port => $self->{port} // 5000,
524 )),
525 quiet => $self->{quiet} // 0,
526 20 ▶ ($self->{loop} ? (loop_type => $self->{loop}) : ()),
Branch: 3 branches
BranchTrueFalseTotal
$has_socket_or_listen ? : 2 18 20
$self->{'loop'} ? : 0 20 20
defined $access_log || $disable_log ? : 20 0 20
Condition55%5/9
$self->{"host"} // "127.0.0.1"
l!l
018
$self->{"port"} // 5000
l!l
108
$self->{"quiet"} // 0
l!l
200
defined $access_log or $disable_log
l!l&&r!l&&!r
0200
MC/DC0%0/1
$self->{"host"} // "127.0.0.1"
$self->{"host"}
MC/DC100%1/1
$self->{"port"} // 5000
$self->{"port"}
MC/DC0%0/1
$self->{"quiet"} // 0
$self->{"quiet"}
MC/DC0%0/2
defined $access_log or $disable_log
defined $access_log $disable_log
Truth table50%1/2
A
A= $self->{"host"}
Aresult
11
00
Truth table100%2/2
A
A= $self->{"port"}
Aresult
11
00
Truth table50%1/2
A
A= $self->{"quiet"}
Aresult
11
00
Truth table33%1/3
A or B
A= defined $access_logB= $disable_log
ABresult
1X1
011
000
527 (defined $access_log || $disable_log
528 ? (access_log => $access_log) : ()),
529 %server_opts,
530 );
531 }
532  
533  
534 =head2 run
535  
536 PAGI::Server::Runner->run(@ARGV);
537 $runner->run(@ARGV);
538  
539 Main entry point. Parses options, loads the app, creates the server,
540 and delegates to C<< $server->run() >> which manages the event loop.
541  
542 =cut
543  
544 # Package variable for END block cleanup
545 16 our $_current_runner;
546  
547 sub run {
548 10 ▶ my $self = shift;
Subroutine run: called CC=9 SCAR=27.2
Pod documented
549  
550 # Support both class and instance method
551 10 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 10 0 10
552 10 $self = $self->new;
553 }
554  
555 # Parse options
556 10 $self->parse_options(@_);
557  
558 # Export resolved mode to environment so apps can check it
559 # (similar to Plack's PLACK_ENV)
560 10 $ENV{PAGI_ENV} = $self->mode;
561  
562 # Configure Future::IO for IO::Async if available
563 # This enables Future::IO-based libraries (Async::Redis, etc.) and
564 # PAGI::SSE->every() to work seamlessly under pagi-server
565 10 $self->_configure_future_io;
566  
567 # Handle --version
568 10 ▶ if ($self->{show_version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_version"}) 0 10 10
569 0 $self->_show_version;
570 0 return;
571 }
572  
573 # Handle --help
574 10 ▶ if ($self->{show_help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"show_help"}) 0 10 10
575 0 $self->_show_help;
576 0 return;
577 }
578  
579 # Prepare app (load + wrap with middleware)
580 10 $self->prepare_app;
581  
582 # Create server
583 10 my $server = $self->load_server;
584  
585 # Daemonize before running (bind errors will be lost in daemon mode,
586 # but this is acceptable for production where systemd/docker is preferred)
587 9 ▶ if ($self->{daemonize}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"daemonize"}) 0 9 9
588 0 $self->_daemonize;
589 }
590  
591 # Write PID file (after daemonizing so we record the daemon's PID)
592 9 ▶ if ($self->{pid_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pid_file"}) 0 9 9
593 0 $self->_write_pid_file($self->{pid_file});
594 # Store for END block cleanup
595 0 $_current_runner = $self;
596 }
597  
598 # Drop privileges
599 9 ▶ if ($self->{user} || $self->{group}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"user"} or $self->{"group"}) 0 9 9
Condition33%1/3
$self->{"user"} or $self->{"group"}
l!l&&r!l&&!r
009
MC/DC0%0/2
$self->{"user"} or $self->{"group"}
$self->{"user"} $self->{"group"}
Truth table33%1/3
A or B
A= $self->{"user"}B= $self->{"group"}
ABresult
1X1
011
000
600 0 $self->_drop_privileges;
601 }
602  
603 # Run server (server owns the event loop)
604 9 $server->run;
605  
606 # Cleanup PID file on normal exit
607 6 ▶ $self->_remove_pid_file if $self->{_pid_file_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_pid_file_path"} 0 6 6
608 }
609  
610 # END block for PID file cleanup on abnormal exit
611 END {
612 15 ▶ if ($_current_runner && $_current_runner->{_pid_file_path}) {
Subroutine END: called CC=3 SCAR=15.4
Branch: 1 branch
BranchTrueFalseTotal
if ($PAGI::Server::Runner::_current_runner and $PAGI::Server::Runner::_current_runner->{"_pid_file_path"}) 0 15 15
Condition33%1/3
$PAGI::Server::Runner::_current_runner and $PAGI::Server::Runner::_current_runner->{"_pid_file_path"}
!ll&&!rl&&r
1500
MC/DC0%0/2
$PAGI::Server::Runner::_current_runner and $PAGI::Server::Runner::_current_runner->{"_pid_file_path"}
$PAGI::Server::Runner::_current_runner $PAGI::Server::Runner::_current_runner->{"_pid_file_path"}
Truth table33%1/3
A and B
A= $PAGI::Server::Runner::_current_runnerB= $PAGI::Server::Runner::_current_runner->{"_pid_file_path"}
ABresult
0X0
100
111
613 0 $_current_runner->_remove_pid_file;
614 }
615 }
616  
617 # Internal methods
618  
619 sub _configure_future_io {
620 10 ▶ my ($self) = @_;
Subroutine _configure_future_io: called CC=4 SCAR=15.5
621  
622 # Try to configure Future::IO for IO::Async
623 # This enables seamless use of Future::IO-based libraries under pagi-server
624 10 my $configured = eval {
625 10 require Future::IO::Impl::IOAsync;
626 10 1;
627 };
628  
629 10 ▶ if ($configured) {
Branch: 1 branch
BranchTrueFalseTotal
if ($configured) 10 0 10
630 # Report in non-production mode
631 10 ▶ if ($self->mode ne 'production' && !$self->{quiet}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mode ne "production" and not $self->{"quiet"}) 0 10 10
Condition33%1/3
$self->mode ne "production" and not $self->{"quiet"}
!ll&&!rl&&r
1000
MC/DC0%0/2
$self->mode ne "production" and not $self->{"quiet"}
$self->mode ne "production" not $self->{"quiet"}
Truth table33%1/3
A and not(B)
A= $self->mode ne "production"B= not $self->{"quiet"}
ABresult
0X0
100
111
632 0 warn "Future::IO configured for IO::Async\n";
633 }
634 }
635 # If Future::IO::Impl::IOAsync not installed, that's fine - user just
636 # won't have Future::IO integration. Apps that need it will get a
637 # helpful error message from PAGI::SSE->every() or similar.
638 }
639  
640 sub _is_module_name {
641 26 ▶ my ($self, $spec) = @_;
Subroutine _is_module_name: called CC=1 SCAR=0.0
642 26 return $spec =~ /::/;
643 }
644  
645 sub _is_file_path {
646 26 ▶ my ($self, $spec) = @_;
Subroutine _is_file_path: called CC=2 SCAR=6.9
647 26 ▶ return $spec =~ m{/} || $spec =~ /\.(?:pl|psgi)$/i;
Condition100%3/3
$spec =~ m[/] || $spec =~ /\.(?:pl|psgi)$/i
l!l&&r!l&&!r
2033
MC/DC100%2/2
$spec =~ m[/] || $spec =~ /\.(?:pl|psgi)$/i
$spec =~ m[/] $spec =~ /\.(?:pl|psgi)$/i
Truth table100%3/3
A || B
A= $spec =~ m[/]B= $spec =~ /\.(?:pl|psgi)$/i
ABresult
1X1
011
000
648 }
649  
650 sub _load_module {
651 3 ▶ my ($self, $module, %args) = @_;
Subroutine _load_module: called CC=5 SCAR=16.2
652  
653 # Validate module name (basic security check)
654 3 ▶ die "Invalid module name: $module\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*$/ 0 3 3
655 unless $module =~ /^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*$/;
656  
657 # Try to load the module
658 3 my $file = $module;
659 3 $file =~ s{::}{/}g;
660 3 $file .= '.pm';
661  
662 3 eval { require $file };
663 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 2 3
664 1 die "Cannot find module '$module': $@\n";
665 }
666  
667 2 ▶ die "Module '$module' does not have a new() method\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $module->can("new") 0 2 2
668 unless $module->can('new');
669  
670 # Get the module's actual file path for correct home directory detection
671 2 my $module_file = $INC{$file};
672  
673 # Instantiate, then normalize the resulting value. Discovery may produce
674 # either a native PAGI coderef or an application-provider object.
675 2 my $instance = eval { $module->new(%args, _caller_file => $module_file) };
676 2 ▶ die "Error constructing module '$module': $@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
677  
678 2 return PAGI::Server::AppNormalizer::normalize_app(
679 $instance,
680 "Module '$module' constructor",
681 );
682 }
683  
684 sub _load_file {
685 19 ▶ my ($self, $file) = @_;
Subroutine _load_file: called CC=6 SCAR=19.3
686  
687 # Convert to absolute path
688 19 $file = File::Spec->rel2abs($file);
689  
690 19 ▶ die "App file not found: $file\n" unless -f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 1 18 19
691  
692 # Match plackup behavior so FindBin::Bin resolves to the app file directory
693 18 local $0 = $file;
694 18 local @ARGV = ($file);
695 18 ▶ if (exists $INC{'FindBin.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{"FindBin.pm"}) 18 0 18
696 18 FindBin::again();
697 }
698  
699 18 my $app = do $file;
700  
701 18 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 18 18
702 0 die "Error loading $file: $@\n";
703 }
704 18 ▶ if (!defined $app && $!) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $app and $!) 0 18 18
Condition33%1/3
not defined $app and $!
!ll&&!rl&&r
1800
MC/DC0%0/2
not defined $app and $!
not defined $app $!
Truth table33%1/3
not(A) and B
A= not defined $appB= $!
ABresult
0X0
100
111
705 0 die "Error reading $file: $!\n";
706 }
707 18 return PAGI::Server::AppNormalizer::normalize_app($app, 'App file');
708 }
709  
710 sub _parse_app_args {
711 23 ▶ my ($self, @args) = @_;
Subroutine _parse_app_args: called CC=3 SCAR=11.3
712  
713 23 my %result;
714 23 for my $arg (@args) {
715 4 ▶ if ($arg =~ /^([^=]+)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^([^=]+)=(.*)$/) { } 4 0 4
716 4 $result{$1} = $2;
717 }
718 else {
719 0 warn "Ignoring argument without '=': $arg\n";
720 }
721 }
722 23 return %result;
723 }
724  
725 sub _show_help {
726 0 ▶ my ($self) = @_;
Subroutine _show_help: not called CC=1 SCAR=6.9
727  
728 0 print <<'HELP';
729 Usage: pagi-server [options] [app] [key=value ...]
730  
731 Common Options (handled by Runner):
732 -I, --lib PATH Add PATH to @INC (repeatable, like perl -I)
733 -a, --app FILE Load app from file (legacy option)
734 -o, --host HOST Bind address (default: 127.0.0.1)
735 -p, --port PORT Bind port (default: 5000)
736 -s, --server CLASS Server class (default: PAGI::Server)
737 -E, --env MODE Environment mode (development, production, none)
738 -l, --loop BACKEND Event loop backend (EV, Epoll, UV, Poll)
739 --access-log FILE Access log file (default: STDERR)
740 --no-access-log Disable access logging
741 -D, --daemonize Run as background daemon
742 --pid FILE Write PID to file
743 --user USER Run as specified user (after binding)
744 --group GROUP Run as specified group (after binding)
745 -q, --quiet Suppress startup messages
746 --no-default-middleware Disable mode-based middleware
747 -v, --version Show version info
748 --help Show this help
749  
750 Environment Modes:
751 development Auto-enable Lint middleware if PAGI-Tools installed (default if TTY)
752 production No auto-middleware (default if no TTY)
753 none Explicit opt-out of all auto-middleware
754  
755 App can be:
756 Module name: pagi-server PAGI::App::Directory root=/var/www
757 File path: pagi-server ./app.pl
758 Default: pagi-server (serves current directory)
759  
760 Server-specific options are handled by the server CLI (e.g., pagi-server).
761 See: perldoc pagi-server
762  
763 HELP
764 }
765  
766 sub _show_version {
767 3 ▶ my ($self) = @_;
Subroutine _show_version: called CC=4 SCAR=14.0
768  
769 3 ▶ my $server_class = $self->{server} // 'PAGI::Server';
Condition50%1/2
$self->{"server"} // "PAGI::Server"
l!l
30
MC/DC0%0/1
$self->{"server"} // "PAGI::Server"
$self->{"server"}
Truth table50%1/2
A
A= $self->{"server"}
Aresult
11
00
770 3 (my $server_file = $server_class) =~ s{::}{/}g;
771 3 eval { require "$server_file.pm" };
772  
773 3 require File::Basename;
774 3 my $prog = File::Basename::basename($0);
775 3 ▶ my $pagi_version = eval { require PAGI; PAGI->VERSION } // 'unknown';
Condition50%1/2
eval { do { require PAGI; "PAGI"->VERSION } } // "unknown"
l!l
03
MC/DC0%0/1
eval { do { require PAGI; "PAGI"->VERSION } } // "unknown"
eval { do { require PAGI; "PAGI"->VERSION } }
Truth table50%1/2
A
A= eval { do { require PAGI; "PAGI"->VERSION } }
Aresult
11
00
776 3 ▶ my $server_version = $server_class->VERSION // 'unknown';
Condition100%2/2
$server_class->VERSION // "unknown"
l!l
21
MC/DC100%1/1
$server_class->VERSION // "unknown"
$server_class->VERSION
Truth table100%2/2
A
A= $server_class->VERSION
Aresult
11
00
777  
778 3 print "$prog (PAGI $pagi_version, $server_class $server_version)\n";
779 }
780  
781 sub _daemonize {
782 0 ▶ my ($self) = @_;
Subroutine _daemonize: not called CC=10 SCAR=47.0
783  
784 # First fork - parent exits, child continues
785 0 my $pid = fork();
786 0 ▶ die "Cannot fork: $!" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
787 0 ▶ exit(0) if $pid; # Parent exits
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 0 0
788  
789 # Child becomes session leader
790 0 ▶ setsid() or die "Cannot create new session: $!";
Branch: 1 branch
BranchTrueFalseTotal
setsid() or die "Cannot create new session: $!" 0 0 0
791  
792 # Second fork - prevent acquiring a controlling terminal
793 0 $pid = fork();
794 0 ▶ die "Cannot fork: $!" unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 0 0
795 0 ▶ exit(0) if $pid; # First child exits
Branch: 1 branch
BranchTrueFalseTotal
if $pid 0 0 0
796  
797 # Grandchild continues as daemon
798 # Change to root directory to avoid blocking unmounts
799 0 ▶ chdir('/') or die "Cannot chdir to /: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir "/" or die "Cannot chdir to /: $!" 0 0 0
800  
801 # Clear umask
802 0 umask(0);
803  
804 # Redirect standard file descriptors to /dev/null
805 0 ▶ open(STDIN, '<', '/dev/null') or die "Cannot redirect STDIN: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<", "/dev/null" or die "Cannot redirect STDIN: $!" 0 0 0
806 0 ▶ open(STDOUT, '>', '/dev/null') or die "Cannot redirect STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">", "/dev/null" or die "Cannot redirect STDOUT: $!" 0 0 0
807 0 ▶ open(STDERR, '>', '/dev/null') or die "Cannot redirect STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", "/dev/null" or die "Cannot redirect STDERR: $!" 0 0 0
808  
809 0 return $$; # Return daemon PID
810 }
811  
812 sub _write_pid_file {
813 3 ▶ my ($self, $pid_file) = @_;
Subroutine _write_pid_file: called CC=2 SCAR=7.0
814  
815 3 ▶ open(my $fh, '>', $pid_file)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $pid_file or die "Cannot write PID file ${pid_file}: $!\n" 0 3 3
816 or die "Cannot write PID file $pid_file: $!\n";
817 3 print $fh "$$\n";
818 3 close($fh);
819  
820 # Store for cleanup
821 3 $self->{_pid_file_path} = $pid_file;
822 }
823  
824 sub _remove_pid_file {
825 4 ▶ my ($self) = @_;
Subroutine _remove_pid_file: called CC=2 SCAR=7.1
826  
827 4 ▶ return unless $self->{_pid_file_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_pid_file_path"} 0 4 4
828 4 unlink($self->{_pid_file_path});
829 }
830  
831 sub _drop_privileges {
832 5 ▶ my ($self) = @_;
Subroutine _drop_privileges: called CC=11 SCAR=39.3
833  
834 5 my $user = $self->{user};
835 5 my $group = $self->{group};
836  
837 5 ▶ return unless $user || $group;
Branch: 1 branch
BranchTrueFalseTotal
unless $user or $group 1 4 5
Condition100%3/3
$user or $group
l!l&&r!l&&!r
221
MC/DC100%2/2
$user or $group
$user $group
Truth table100%3/3
A or B
A= $userB= $group
ABresult
1X1
011
000
838  
839 # Must be root to change user/group
840 4 ▶ if ($> != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($> != 0) 4 0 4
841 4 die "Must run as root to use --user/--group\n";
842 }
843  
844 # Change group first (while still root)
845 0 ▶ if ($group) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group) 0 0 0
846 0 my $gid = getgrnam($group);
847 0 ▶ die "Unknown group: $group\n" unless defined $gid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $gid 0 0 0
848  
849 # Set both real and effective GID
850 0 $( = $) = $gid;
851 0 ▶ die "Cannot change to group $group: $!\n" if $) != $gid;
Branch: 1 branch
BranchTrueFalseTotal
if $) != $gid 0 0 0
852 }
853  
854 # Then change user
855 0 ▶ if ($user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 0 0 0
856 0 my ($uid, $gid) = (getpwnam($user))[2, 3];
857 0 ▶ die "Unknown user: $user\n" unless defined $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uid 0 0 0
858  
859 # If no group specified, use user's primary group
860 0 ▶ unless ($group) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($group) 0 0 0
861 0 $( = $) = $gid;
862 }
863  
864 # Set both real and effective UID
865 0 $< = $> = $uid;
866 0 ▶ die "Cannot change to user $user: $!\n" if $> != $uid;
Branch: 1 branch
BranchTrueFalseTotal
if $> != $uid 0 0 0
867 }
868 }
869  
870 16 1;
871  
872 __END__
« blib/lib/PAGI/Server/Connection.pm ↑ Summary blib/lib/PAGI/Server/Protocol/HTTP1.pm »