| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perl::Server; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
194920
|
use strict; |
|
|
5
|
|
|
|
|
29
|
|
|
|
5
|
|
|
|
|
114
|
|
|
4
|
5
|
|
|
5
|
|
16
|
use warnings; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
92
|
|
|
5
|
5
|
|
|
5
|
|
18
|
use Cwd; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
242
|
|
|
6
|
5
|
|
|
5
|
|
1736
|
use Plack::Runner; |
|
|
5
|
|
|
|
|
64360
|
|
|
|
5
|
|
|
|
|
149
|
|
|
7
|
5
|
|
|
5
|
|
2332
|
use Term::ANSIColor; |
|
|
5
|
|
|
|
|
30312
|
|
|
|
5
|
|
|
|
|
295
|
|
|
8
|
5
|
|
|
5
|
|
2812
|
use Getopt::Long; |
|
|
5
|
|
|
|
|
38059
|
|
|
|
5
|
|
|
|
|
17
|
|
|
9
|
5
|
|
|
5
|
|
2395
|
use Net::EmptyPort qw/empty_port check_port/; |
|
|
5
|
|
|
|
|
125860
|
|
|
|
5
|
|
|
|
|
3739
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
|
14
|
2
|
|
|
2
|
0
|
659
|
my $class = shift; |
|
15
|
2
|
|
|
|
|
4
|
my $path = shift; |
|
16
|
|
|
|
|
|
|
|
|
17
|
2
|
100
|
|
|
|
18
|
return bless { |
|
18
|
|
|
|
|
|
|
path => $path ? $path : getcwd, |
|
19
|
|
|
|
|
|
|
type => '' |
|
20
|
|
|
|
|
|
|
}, $class; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub run { |
|
24
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
25
|
0
|
|
|
|
|
|
my @argv = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
local @ARGV = @argv; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $parser = Getopt::Long::Parser->new( |
|
30
|
|
|
|
|
|
|
config => [ "no_auto_abbrev", "no_ignore_case", "pass_through" ], |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $port; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$parser->getoptions( |
|
36
|
|
|
|
|
|
|
"p|port=s" => \$port |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $type = $self->_type; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $middleware = $self->_middleware; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if (exists $type->{module}) { |
|
44
|
0
|
|
|
|
|
|
push(@argv, '-M'); |
|
45
|
0
|
|
|
|
|
|
push(@argv, $type->{module}); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
push(@argv, '-e'); |
|
48
|
0
|
|
|
|
|
|
push(@argv, $middleware . '; ' . $type->{eval}); |
|
49
|
|
|
|
|
|
|
} else { |
|
50
|
0
|
|
|
|
|
|
push(@argv, '-e'); |
|
51
|
0
|
|
|
|
|
|
push(@argv, $middleware); |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
push(@argv, '-a'); |
|
54
|
0
|
|
|
|
|
|
push(@argv, $type->{app}); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ($port) { |
|
58
|
0
|
|
|
|
|
|
push(@argv, '-p'); |
|
59
|
0
|
0
|
|
|
|
|
push(@argv, $port =~ /^e(mpty)?$/i ? $self->_port(1) : ($port =~ /\D/ ? $self->_port : $port)); |
|
|
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} else { |
|
61
|
0
|
|
|
|
|
|
push(@argv, '-p'); |
|
62
|
0
|
|
|
|
|
|
push(@argv, $self->_port); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$ENV{PLACK_ENV} = 'perl-server'; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $runner = Plack::Runner->new; |
|
68
|
0
|
|
|
|
|
|
$runner->parse_options(@argv); |
|
69
|
0
|
|
|
|
|
|
$runner->prepare_devel($runner); |
|
70
|
0
|
|
|
|
|
|
$self->_message($runner); |
|
71
|
0
|
|
|
|
|
|
$runner->run; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _type { |
|
75
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $path = $self->{path}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $type = {}; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
0
|
0
|
|
|
|
if (-d $path) { |
|
|
|
0
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->{type} = 'Folder'; |
|
83
|
0
|
|
|
|
|
|
$type->{module} = 'Plack::App::WWW'; |
|
84
|
0
|
|
|
|
|
|
$type->{eval} = "Plack::App::WWW->new(root => '$path')->to_app"; |
|
85
|
|
|
|
|
|
|
} elsif (-e $path && $path =~ /\.(pl|cgi)$/i) { |
|
86
|
0
|
|
|
|
|
|
$self->{type} = 'File'; |
|
87
|
0
|
|
|
|
|
|
$type->{module} = 'Plack::App::WrapCGI'; |
|
88
|
0
|
|
|
|
|
|
$type->{eval} = "Plack::App::WrapCGI->new(script => '$path')->to_app"; |
|
89
|
|
|
|
|
|
|
} else { |
|
90
|
0
|
|
|
|
|
|
$self->{type} = 'PSGI'; |
|
91
|
0
|
|
|
|
|
|
$type->{app} = $path; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $type; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _message { |
|
98
|
0
|
|
|
0
|
|
|
my ($self, $runner) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
push @{$runner->{options}}, server_ready => sub { |
|
101
|
0
|
|
|
0
|
|
|
my $args = shift; |
|
102
|
0
|
|
0
|
|
|
|
my $server = $args->{server_software} || ref($args); |
|
103
|
0
|
|
0
|
|
|
|
my $host = $args->{host} || 0; |
|
104
|
0
|
|
0
|
|
|
|
my $proto = $args->{proto} || 'http'; |
|
105
|
0
|
|
|
|
|
|
my $port = $args->{port}; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
$self->_name; |
|
108
|
0
|
|
|
|
|
|
$self->_print('Version', $VERSION); |
|
109
|
0
|
|
|
|
|
|
$self->_print('Server', $server); |
|
110
|
0
|
|
|
|
|
|
$self->_print('Type', $self->{type}); |
|
111
|
0
|
|
|
|
|
|
$self->_print('Path', $self->{path}); |
|
112
|
0
|
|
|
|
|
|
$self->_print('Available on', "$proto://$host:$port"); |
|
113
|
0
|
|
|
|
|
|
$self->_stop; |
|
114
|
0
|
|
|
|
|
|
}; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub _middleware { |
|
118
|
0
|
|
|
0
|
|
|
my $middleware = 'enable "AccessLog", format => \'%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"\''; |
|
119
|
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return $middleware; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _port { |
|
124
|
0
|
|
|
0
|
|
|
my ($self, $rand) = @_; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
0
|
|
|
|
|
return empty_port if $rand; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $port = 3000; |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
return $port unless check_port($port); |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
while ($port++ < 65000) { |
|
133
|
0
|
0
|
|
|
|
|
last unless check_port($port); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $port; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _name { |
|
140
|
0
|
|
|
0
|
|
|
print STDERR color('bold blue'); |
|
141
|
0
|
|
|
|
|
|
print STDERR "Perl::Server\n\n"; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub _stop { |
|
145
|
0
|
|
|
0
|
|
|
print STDERR color('reset'); |
|
146
|
0
|
|
|
|
|
|
print STDERR color('white'); |
|
147
|
0
|
|
|
|
|
|
print STDERR "\nHit CTRL-C to stop the perl-server\n\n"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _print { |
|
151
|
0
|
|
|
0
|
|
|
my ($self, $name, $value) = @_; |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
print STDERR color('reset'); |
|
154
|
0
|
|
|
|
|
|
print STDERR color('yellow'); |
|
155
|
0
|
|
|
|
|
|
print STDERR "$name: "; |
|
156
|
0
|
|
|
|
|
|
print STDERR color('reset'); |
|
157
|
0
|
|
|
|
|
|
print STDERR color('green'); |
|
158
|
0
|
|
|
|
|
|
print STDERR "$value\n"; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
__END__ |