Mercury/Command/mercury/broker.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 4 / 10 Podpod 100% 1 / 1 totaltotal 42.0% 21 / 50 CC 5 SCAR 24.6
CC
5
Cov
41%
run
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 11.7
↑ Summary Mercury.pm »
1 package Mercury::Command::mercury::broker;
2 1 our $VERSION = '0.016';
3 # ABSTRACT: Mercury message broker command
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod Usage: mercury broker [OPTIONS]
8 #pod
9 #pod mercury broker
10 #pod mercury broker -m production -l http://*:8080
11 #pod mercury broker -l http://127.0.0.1:8080 -l https://[::]:8081
12 #pod mercury broker -l 'https://*:443?cert=./server.crt&key=./server.key'
13 #pod
14 #pod Options:
15 #pod -m, --mode <mode> Set the mode, defaults to the value
16 #pod of MOJO_MODE, PLACK_ENV, or
17 #pod "development"
18 #pod -b, --backlog <size> Listen backlog size, defaults to
19 #pod SOMAXCONN
20 #pod -c, --clients <number> Maximum number of concurrent
21 #pod connections, defaults to 1000
22 #pod -i, --inactivity-timeout <seconds> Inactivity timeout, defaults to 4
23 #pod hours
24 #pod -l, --listen <location> One or more locations you want to
25 #pod listen on, defaults to the value of
26 #pod MOJO_LISTEN or "http://*:3000"
27 #pod -p, --proxy Activate reverse proxy support,
28 #pod defaults to the value of
29 #pod MOJO_REVERSE_PROXY
30 #pod
31 #pod =head1 DESCRIPTION
32 #pod
33 #pod L<Mercury::Command::broker> starts the L<Mercury> application.
34 #pod
35 #pod =cut
36  
37 1 ▶use Mojo::Base 'Mojolicious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use Mercury;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 ▶use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Mojo::Server::Daemon;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 #pod =attr description
44 #pod
45 #pod my $description = $cmd->description;
46 #pod $cmd = $cmd->description('Foo');
47 #pod
48 #pod Short description of this command, used for the command list.
49 #pod
50 #pod =cut
51  
52 1 has description => 'Start WebSocket message broker';
53  
54 #pod =attr usage
55 #pod
56 #pod my $usage = $cmd->usage;
57 #pod $cmd = $cmd->usage('Foo');
58 #pod
59 #pod Usage information for this command, used for the help screen.
60 #pod
61 #pod =cut
62  
63 0 ▶has usage => sub { shift->extract_usage };
Subroutine __ANON__: not called CC=1 SCAR=1.2
64  
65 #pod =method run
66 #pod
67 #pod $cmd->run(@ARGV);
68 #pod
69 #pod Run this command.
70 #pod
71 #pod =cut
72  
73 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod documented
74 0 my ( $self, @args ) = @_;
75  
76 # If we're started with the 'mercury' script, we're our own app and we need
77 # to serve ourselves. This ensures that the initialization already done
78 # isn't done twice.
79 0 ▶ my $app = $self->app->isa( 'Mercury' ) ? $self->app : Mercury->new;
Branch: 1 branch
BranchTrueFalseTotal
$self->app->isa('Mercury') ? : 0 0 0
80  
81 0 my $daemon = Mojo::Server::Daemon->new(
82 app => $app,
83 inactivity_timeout => 4 * 60 * 60,
84 );
85  
86 GetOptionsFromArray( \@args,
87 0 ▶ 'b|backlog=i' => sub { $daemon->backlog($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 ▶ 'c|clients=i' => sub { $daemon->max_clients($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 0 ▶ 'i|inactivity-timeout=i' => sub { $daemon->inactivity_timeout($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 'l|listen=s' => \my @listen,
91 0 ▶ 'p|proxy' => sub { $daemon->reverse_proxy(1) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 );
93  
94 0 ▶ if ( @listen ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@listen) { } 0 0 0
elsif (my $conf = eval { do { $app->config->{'broker'} } }) { } 0 0 0
95 0 $daemon->listen(\@listen);
96 }
97 0 elsif ( my $conf = eval { $app->config->{ broker } } ) {
98 0 ▶ if ( $conf->{listen} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf->{"listen"}) 0 0 0
99 0 $daemon->listen( [ $conf->{listen} ] );
100 }
101 }
102  
103 0 $daemon->run;
104 }
105  
106 1 1;
107  
108 __END__
↑ Summary Mercury.pm »