Mojolicious/Command/prefork.pm

filter: Statementstmt 65.7% 23 / 35 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 6 / 18 Podpod 100% 2 / 2 totaltotal 60.3% 38 / 63 CC 5 SCAR 10.7
CC
5
Cov
70%
build_server
7.3
__ANON__
2.0
__ANON__
2.0
CRAP 2.9
« Mojo/IOLoop.pm ↑ Summary Mojolicious/Command/daemon.pm »
1 package Mojolicious::Command::prefork;
2 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Mojo::Server::Prefork;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mojo::Util qw(getopt);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 has description => 'Start application with pre-forking HTTP and WebSocket server';
8 2 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 5 ▶sub build_server {
Subroutine build_server: called CC=5 SCAR=19.8
Pod documented
11 5 my ($self, @args) = @_;
12  
13 5 my $prefork = Mojo::Server::Prefork->new(app => $self->app);
14 die $self->usage
15 unless getopt \@args,
16 0 ▶ 'a|accepts=i' => sub { $prefork->accepts($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 0 ▶ 'b|backlog=i' => sub { $prefork->backlog($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 ▶ 'c|clients=i' => sub { $prefork->max_clients($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
19 0 ▶ 'G|graceful-timeout=i' => sub { $prefork->graceful_timeout($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 0 ▶ 'I|heartbeat-interval=i' => sub { $prefork->heartbeat_interval($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶ 'H|heartbeat-timeout=i' => sub { $prefork->heartbeat_timeout($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 ▶ 'i|inactivity-timeout=i' => sub { $prefork->inactivity_timeout($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 0 ▶ 'k|keep-alive-timeout=i' => sub { $prefork->keep_alive_timeout($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 'l|listen=s' => \my @listen,
25 0 ▶ 'P|pid-file=s' => sub { $prefork->pid_file($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 'p|proxy:s' => \my @proxy,
27 0 ▶ 'r|requests=i' => sub { $prefork->max_requests($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 ▶ 's|spare=i' => sub { $prefork->spare($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 ▶ 'w|workers=i' => sub { $prefork->workers($_[1]) };
Subroutine __ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless getopt(\@args, "a|accepts=i", sub { $prefork->accepts($_[1]); } , "b|backlog=i", sub { $prefork->backlog($_[1]); } , "c|clients=i", sub { $prefork->max_clients($_[1]); } , "G|graceful-timeout=i", sub { $prefork->graceful_timeout($_[1]); } , "I|heartbeat-interval=i", sub { $prefork->heartbeat_interval($_[1]); } , "H|heartbeat-timeout=i", sub { $prefork->heartbeat_timeout($_[1]); } , "i|inactivity-timeout=i", sub { $prefork->inactivity_timeout($_[1]); } , "k|keep-alive-timeout=i", sub { $prefork->keep_alive_timeout($_[1]); } , "l|listen=s", \my @listen, "P|pid-file=s", sub { $prefork->pid_file($_[1]); } , "p|proxy:s", \my @proxy, "r|requests=i", sub { $prefork->max_requests($_[1]); } , "s|spare=i", sub { $prefork->spare($_[1]); } , "w|workers=i", sub { $prefork->workers($_[1]); } ) 1 4 5
30  
31 4 ▶ $prefork->listen(\@listen) if @listen;
Branch: 1 branch
BranchTrueFalseTotal
if @listen 0 4 4
32 4 ▶ $prefork->reverse_proxy(1) if @proxy;
Branch: 1 branch
BranchTrueFalseTotal
if @proxy 3 1 4
33 4 my @trusted = grep {length} @proxy;
34 4 ▶ $prefork->trusted_proxies(\@trusted) if @trusted;
Branch: 1 branch
BranchTrueFalseTotal
if @trusted 2 2 4
35 4 return $prefork;
36 }
37  
38 1 ▶sub run { shift->build_server(@_)->run }
Subroutine run: called CC=1 SCAR=0.0
Pod documented
39  
40 1 1;
41  
42 =encoding utf8
43  
44 =head1 NAME
45  
46 Mojolicious::Command::prefork - Pre-fork command
47  
48 =head1 SYNOPSIS
49  
50 Usage: APPLICATION prefork [OPTIONS]
51  
52 ./myapp.pl prefork
53 ./myapp.pl prefork -m production -p -l http://*:8080
54 ./myapp.pl prefork -l http://127.0.0.1:8080 -l https://[::]:8081
55 ./myapp.pl prefork -l 'https://*:443?cert=./server.crt&key=./server.key'
56 ./myapp.pl prefork -l http+unix://%2Ftmp%2Fmyapp.sock -w 12
57 ./myapp.pl prefork -l http://127.0.0.1:8080 -p 127.0.0.0/8 -p fc00::/7
58  
59 Options:
60 -a, --accepts <number> Number of connections for workers to
61 accept, defaults to 10000
62 -b, --backlog <size> Listen backlog size, defaults to
63 SOMAXCONN
64 -c, --clients <number> Maximum number of concurrent
65 connections, defaults to 1000
66 -G, --graceful-timeout <seconds> Graceful timeout, defaults to 120.
67 -I, --heartbeat-interval <seconds> Heartbeat interval, defaults to 5
68 -H, --heartbeat-timeout <seconds> Heartbeat timeout, defaults to 50
69 -h, --help Show this summary of available options
70 --home <path> Path to home directory of your
71 application, defaults to the value of
72 MOJO_HOME or auto-detection
73 -i, --inactivity-timeout <seconds> Inactivity timeout, defaults to the
74 value of MOJO_INACTIVITY_TIMEOUT or 30
75 -k, --keep-alive-timeout <seconds> Keep-alive timeout, defaults to the
76 value of MOJO_KEEP_ALIVE_TIMEOUT or 5
77 -l, --listen <location> One or more locations you want to
78 listen on, defaults to the value of
79 MOJO_LISTEN or "http://*:3000"
80 -m, --mode <name> Operating mode for your application,
81 defaults to the value of
82 MOJO_MODE/PLACK_ENV or "development"
83 -P, --pid-file <path> Path to process id file, defaults to
84 "prefork.pid" in a temporary directory
85 -p, --proxy [<network>] Activate reverse proxy support,
86 defaults to the value of
87 MOJO_REVERSE_PROXY, optionally takes
88 one or more trusted proxy addresses or
89 networks
90 -r, --requests <number> Maximum number of requests per
91 keep-alive connection, defaults to 100
92 -s, --spare <number> Temporarily spawn up to this number of
93 additional workers, defaults to 2
94 -w, --workers <number> Number of workers, defaults to 4
95  
96 =head1 DESCRIPTION
97  
98 L<Mojolicious::Command::prefork> starts applications with the L<Mojo::Server::Prefork> backend.
99  
100 This is a core command, that means it is always enabled and its code a good example for learning to build new commands,
101 you're welcome to fork it.
102  
103 See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are available by default.
104  
105 =head1 ATTRIBUTES
106  
107 L<Mojolicious::Command::prefork> inherits all attributes from L<Mojolicious::Command> and implements the following new
108 ones.
109  
110 =head2 description
111  
112 my $description = $prefork->description;
113 $prefork = $prefork->description('Foo');
114  
115 Short description of this command, used for the command list.
116  
117 =head2 usage
118  
119 my $usage = $prefork->usage;
120 $prefork = $prefork->usage('Foo');
121  
122 Usage information for this command, used for the help screen.
123  
124 =head1 METHODS
125  
126 L<Mojolicious::Command::prefork> inherits all methods from L<Mojolicious::Command> and implements the following new
127 ones.
128  
129 =head2 build_server
130  
131 my $server = $daemon->build_server(@ARGV);
132  
133 Build L<Mojo::Server::Prefork> instance from command line arguments.
134  
135 =head2 run
136  
137 $prefork->run(@ARGV);
138  
139 Run this command.
140  
141 =head1 SEE ALSO
142  
143 L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
144  
145 =cut
« Mojo/IOLoop.pm ↑ Summary Mojolicious/Command/daemon.pm »