Mojolicious/Command/daemon.pm

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