line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Server; |
2
|
54
|
|
|
54
|
|
414
|
use Mojo::Base -base; |
|
54
|
|
|
|
|
136
|
|
|
54
|
|
|
|
|
416
|
|
3
|
|
|
|
|
|
|
|
4
|
54
|
|
|
54
|
|
402
|
use Mojo::IOLoop; |
|
54
|
|
|
|
|
143
|
|
|
54
|
|
|
|
|
330
|
|
5
|
54
|
|
|
54
|
|
22957
|
use Mojo::Server::Daemon; |
|
54
|
|
|
|
|
204
|
|
|
54
|
|
|
|
|
530
|
|
6
|
54
|
|
|
54
|
|
379
|
use Scalar::Util qw(weaken); |
|
54
|
|
|
|
|
155
|
|
|
54
|
|
|
|
|
37238
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has ioloop => sub { Mojo::IOLoop->singleton }; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub app { |
11
|
384
|
|
|
384
|
1
|
1171
|
my ($self, $app) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Singleton application |
14
|
384
|
|
|
|
|
629
|
state $singleton; |
15
|
384
|
100
|
|
|
|
1552
|
return $singleton = $app ? $app : $singleton unless ref $self; |
|
|
100
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Default to singleton application |
18
|
274
|
100
|
66
|
|
|
2936
|
return $self->{app} || $singleton unless $app; |
19
|
15
|
|
|
|
|
59
|
$self->{app} = $app; |
20
|
15
|
|
|
|
|
41
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
49
|
|
|
49
|
1
|
180
|
sub nb_url { shift->_url(1, @_) } |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
1
|
15
|
sub restart { delete @{$_[0]}{qw(nb_port nb_server port server)} } |
|
4
|
|
|
|
|
29
|
|
26
|
|
|
|
|
|
|
|
27
|
868
|
|
|
868
|
1
|
2882
|
sub url { shift->_url(0, @_) } |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _url { |
30
|
917
|
|
|
917
|
|
2263
|
my ($self, $nb, $proto) = @_; |
31
|
|
|
|
|
|
|
|
32
|
917
|
100
|
66
|
|
|
4465
|
if (!$self->{server} || $proto) { |
33
|
64
|
|
50
|
|
|
507
|
$proto = $self->{proto} = $proto || 'http'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Blocking |
36
|
64
|
|
|
|
|
376
|
my $server = $self->{server} = Mojo::Server::Daemon->new(ioloop => $self->ioloop, silent => 1); |
37
|
64
|
|
|
|
|
398
|
weaken $server->app($self->app)->{app}; |
38
|
64
|
50
|
|
|
|
394
|
my $port = $self->{port} ? ":$self->{port}" : ''; |
39
|
64
|
|
|
|
|
540
|
$self->{port} = $server->listen(["$proto://127.0.0.1$port"])->start->ports->[0]; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Non-blocking |
42
|
64
|
|
|
|
|
4001
|
$server = $self->{nb_server} = Mojo::Server::Daemon->new(silent => 1); |
43
|
64
|
|
|
|
|
347
|
weaken $server->app($self->app)->{app}; |
44
|
64
|
50
|
|
|
|
408
|
$port = $self->{nb_port} ? ":$self->{nb_port}" : ''; |
45
|
64
|
|
|
|
|
437
|
$self->{nb_port} = $server->listen(["$proto://127.0.0.1$port"])->start->ports->[0]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
917
|
100
|
|
|
|
6368
|
my $port = $nb ? $self->{nb_port} : $self->{port}; |
49
|
917
|
|
|
|
|
4500
|
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 |