line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Server; |
2
|
53
|
|
|
53
|
|
407
|
use Mojo::Base -base; |
|
53
|
|
|
|
|
124
|
|
|
53
|
|
|
|
|
382
|
|
3
|
|
|
|
|
|
|
|
4
|
53
|
|
|
53
|
|
366
|
use Mojo::IOLoop; |
|
53
|
|
|
|
|
154
|
|
|
53
|
|
|
|
|
320
|
|
5
|
53
|
|
|
53
|
|
20982
|
use Mojo::Server::Daemon; |
|
53
|
|
|
|
|
173
|
|
|
53
|
|
|
|
|
490
|
|
6
|
53
|
|
|
53
|
|
370
|
use Scalar::Util qw(weaken); |
|
53
|
|
|
|
|
133
|
|
|
53
|
|
|
|
|
34126
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has ioloop => sub { Mojo::IOLoop->singleton }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub app { |
11
|
378
|
|
|
378
|
1
|
1031
|
my ($self, $app) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Singleton application |
14
|
378
|
|
|
|
|
570
|
state $singleton; |
15
|
378
|
100
|
|
|
|
1393
|
return $singleton = $app ? $app : $singleton unless ref $self; |
|
|
100
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Default to singleton application |
18
|
270
|
100
|
66
|
|
|
2319
|
return $self->{app} || $singleton unless $app; |
19
|
15
|
|
|
|
|
49
|
$self->{app} = $app; |
20
|
15
|
|
|
|
|
39
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
49
|
|
|
49
|
1
|
142
|
sub nb_url { shift->_url(1, @_) } |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
1
|
12
|
sub restart { delete @{$_[0]}{qw(nb_port nb_server port server)} } |
|
4
|
|
|
|
|
24
|
|
26
|
|
|
|
|
|
|
|
27
|
856
|
|
|
856
|
1
|
2925
|
sub url { shift->_url(0, @_) } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _url { |
30
|
905
|
|
|
905
|
|
2148
|
my ($self, $nb, $proto) = @_; |
31
|
|
|
|
|
|
|
|
32
|
905
|
100
|
66
|
|
|
4377
|
if (!$self->{server} || $proto) { |
33
|
63
|
|
50
|
|
|
460
|
$proto = $self->{proto} = $proto || 'http'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Blocking |
36
|
63
|
|
|
|
|
566
|
my $server = $self->{server} = Mojo::Server::Daemon->new(ioloop => $self->ioloop, silent => 1); |
37
|
63
|
|
|
|
|
290
|
weaken $server->app($self->app)->{app}; |
38
|
63
|
50
|
|
|
|
352
|
my $port = $self->{port} ? ":$self->{port}" : ''; |
39
|
63
|
|
|
|
|
435
|
$self->{port} = $server->listen(["$proto://127.0.0.1$port"])->start->ports->[0]; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Non-blocking |
42
|
63
|
|
|
|
|
4032
|
$server = $self->{nb_server} = Mojo::Server::Daemon->new(silent => 1); |
43
|
63
|
|
|
|
|
303
|
weaken $server->app($self->app)->{app}; |
44
|
63
|
50
|
|
|
|
340
|
$port = $self->{nb_port} ? ":$self->{nb_port}" : ''; |
45
|
63
|
|
|
|
|
370
|
$self->{nb_port} = $server->listen(["$proto://127.0.0.1$port"])->start->ports->[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
905
|
100
|
|
|
|
6027
|
my $port = $nb ? $self->{nb_port} : $self->{port}; |
49
|
905
|
|
|
|
|
4213
|
return Mojo::URL->new("$self->{proto}://127.0.0.1:$port/"); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding utf8 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Mojo::UserAgent::Server - Application server |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Mojo::UserAgent::Server; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $server = Mojo::UserAgent::Server->new; |
65
|
|
|
|
|
|
|
say $server->url; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
L is an embedded web server based on L that processes requests for |
70
|
|
|
|
|
|
|
L. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L implements the following attributes. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 ioloop |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $loop = $server->ioloop; |
79
|
|
|
|
|
|
|
$server = $server->ioloop(Mojo::IOLoop->new); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Event loop object to use for I/O operations, defaults to the global L singleton. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 app |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $app = Mojo::UserAgent::Server->app; |
90
|
|
|
|
|
|
|
Mojo::UserAgent::Server->app(Mojolicious->new); |
91
|
|
|
|
|
|
|
my $app = $server->app; |
92
|
|
|
|
|
|
|
$server = $server->app(Mojolicious->new); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Application this server handles, instance specific applications override the global default. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Change application behavior |
97
|
|
|
|
|
|
|
$server->app->defaults(testing => 'oh yea!'); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 nb_url |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $url = $server->nb_url; |
102
|
|
|
|
|
|
|
my $url = $server->nb_url('http'); |
103
|
|
|
|
|
|
|
my $url = $server->nb_url('https'); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Get absolute L object for server processing non-blocking requests with L"app"> and switch protocol if |
106
|
|
|
|
|
|
|
necessary. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 restart |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$server->restart; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Restart server with new port. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 url |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $url = $server->url; |
117
|
|
|
|
|
|
|
my $url = $server->url('http'); |
118
|
|
|
|
|
|
|
my $url = $server->url('https'); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Get absolute L object for server processing blocking requests with L"app"> and switch protocol if |
121
|
|
|
|
|
|
|
necessary. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SEE ALSO |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L, L, L. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |