line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Command::static; |
2
|
1
|
|
|
1
|
|
459
|
use Mojo::Base 'Mojolicious::Command'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# This command is a copy of Mojolicious::Command::daemon |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
41225
|
use Mojo::File 'path'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
7
|
1
|
|
|
1
|
|
412
|
use Mojo::Server::Daemon; |
|
1
|
|
|
|
|
154067
|
|
|
1
|
|
|
|
|
21
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
56
|
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
10
|
1
|
|
|
1
|
|
189
|
use File::Basename; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
658
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has description => 'Quickly serve static files'; |
15
|
|
|
|
|
|
|
has usage => sub { shift->extract_usage }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub run { |
18
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $daemon = Mojo::Server::Daemon->new(app => Mojolicious->new); |
21
|
|
|
|
|
|
|
GetOptionsFromArray \@args, |
22
|
0
|
|
|
0
|
|
|
'b|backlog=i' => sub { $daemon->backlog($_[1]) }, |
23
|
0
|
|
|
0
|
|
|
'c|clients=i' => sub { $daemon->max_clients($_[1]) }, |
24
|
0
|
|
|
0
|
|
|
'i|inactivity-timeout=i' => sub { $daemon->inactivity_timeout($_[1]) }, |
25
|
|
|
|
|
|
|
'l|listen=s' => \my @listen, |
26
|
0
|
|
|
0
|
|
|
'p|proxy' => sub { $daemon->reverse_proxy(1) }, |
27
|
0
|
|
|
0
|
|
|
'r|requests=i' => sub { $daemon->max_requests($_[1]) }; |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
push @{$daemon->app->renderer->classes}, __PACKAGE__; |
|
0
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Add all the paths and paths of filenames specified on the command line |
32
|
0
|
0
|
|
|
|
|
push @args, '.' unless @args; |
33
|
0
|
0
|
|
|
|
|
$daemon->app->static->paths([grep { -d $_ } map { -f $_ ? dirname $_ : $_ } @args]); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$daemon->app->max_request_size(10_000_000_000); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$daemon->app->helper(expand_args => \&_expand_args); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Create numeric shortcuts for each filename specified on the command line |
40
|
0
|
|
|
|
|
|
my @files = $self->_expand_args(\@args); |
41
|
0
|
|
|
|
|
|
$daemon->app->log->info(sprintf 'Currently %d files', $#files+1); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Build an index of the available specified files |
44
|
0
|
|
|
|
|
|
$daemon->app->routes->get('/')->name('index')->to(args => \@args); |
45
|
|
|
|
|
|
|
$daemon->app->hook(after_static => sub { |
46
|
0
|
|
|
0
|
|
|
my $c = shift; |
47
|
0
|
|
|
|
|
|
$c->app->log->info(sprintf 'GET %s', $c->req->url->path); |
48
|
0
|
|
|
|
|
|
}); |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
$daemon->listen(\@listen) if @listen; |
51
|
0
|
|
|
|
|
|
$daemon->run; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _expand_args { |
55
|
0
|
|
|
0
|
|
|
my ($self, $args) = @_; |
56
|
0
|
|
|
|
|
|
my @files; |
57
|
0
|
|
|
|
|
|
foreach my $path ( map { path($_) } @$args ) { |
|
0
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( -d $path ) { |
59
|
|
|
|
|
|
|
#$path->list_tree->each(sub{push @files, $_->to_rel($_->to_array->[0])}); |
60
|
0
|
|
|
0
|
|
|
$path->list_tree->each(sub{push @files, $_->to_rel($path)}); |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
push @files, $path->to_rel($path->to_array->[0]); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
return @files; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=encoding utf8 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Mojolicious::Command::static - Quickly serve static files |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SYNOPSIS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Usage: APPLICATION static [OPTIONS] dir1 dir2 ... file1 file2 ... |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
./myapp.pl static |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Options: |
83
|
|
|
|
|
|
|
-h, --help Show this summary of available options |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 DESCRIPTION |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L quickly serves static files |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Serves files from the current directory as well as those specified on the |
90
|
|
|
|
|
|
|
command line. Numeric shortcuts (e.g. /1, /2, etc) are created for files |
91
|
|
|
|
|
|
|
that are specified on the command line. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L inherits all attributes from |
96
|
|
|
|
|
|
|
L and implements the following new ones. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 description |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $description = $static->description; |
101
|
|
|
|
|
|
|
$static = $static->description('Foo'); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Short description of this command, used for the command list. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 usage |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $usage = $static->usage; |
108
|
|
|
|
|
|
|
$routes = $static->usage('Foo'); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Usage information for this command, used for the help screen. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L inherits all methods from |
115
|
|
|
|
|
|
|
L and implements the following new ones. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 run |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$static->run(@ARGV); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Run this command. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SEE ALSO |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L, L, L. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__DATA__ |