| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: HiD 'server' subcmd - start up a Plack-based web server for your site |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package HiD::App::Command::server; |
|
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GENEHACK'; |
|
6
|
|
|
|
|
|
|
$HiD::App::Command::server::VERSION = '1.991'; |
|
7
|
4
|
|
|
4
|
|
2511
|
use Moose; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
30
|
|
|
8
|
|
|
|
|
|
|
extends 'HiD::App::Command'; |
|
9
|
|
|
|
|
|
|
with 'HiD::Role::PublishesDrafts'; |
|
10
|
4
|
|
|
4
|
|
24120
|
use namespace::autoclean; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
42
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
360
|
use 5.014; # strict, unicode_strings |
|
|
4
|
|
|
|
|
14
|
|
|
13
|
4
|
|
|
4
|
|
19
|
use utf8; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
31
|
|
|
14
|
4
|
|
|
4
|
|
100
|
use autodie; |
|
|
4
|
|
|
|
|
16
|
|
|
|
4
|
|
|
|
|
30
|
|
|
15
|
4
|
|
|
4
|
|
18498
|
use warnings qw/ FATAL utf8 /; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
194
|
|
|
16
|
4
|
|
|
4
|
|
22
|
use open qw/ :std :utf8 /; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
36
|
|
|
17
|
4
|
|
|
4
|
|
585
|
use charnames qw/ :full /; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
32
|
|
|
18
|
4
|
|
|
4
|
|
958
|
use feature qw/ unicode_strings /; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
436
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
4
|
|
|
4
|
|
27
|
use Class::Load qw/ try_load_class /; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
242
|
|
|
21
|
4
|
|
|
4
|
|
1580
|
use Plack::Builder; |
|
|
4
|
|
|
|
|
28965
|
|
|
|
4
|
|
|
|
|
272
|
|
|
22
|
4
|
|
|
4
|
|
1090
|
use Plack::Runner; |
|
|
4
|
|
|
|
|
6822
|
|
|
|
4
|
|
|
|
|
112
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
4
|
|
|
4
|
|
1233
|
use HiD::Server; |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
124
|
|
|
25
|
4
|
|
|
4
|
|
1102
|
use HiD::Server::Handler; |
|
|
4
|
|
|
|
|
14
|
|
|
|
4
|
|
|
|
|
141
|
|
|
26
|
4
|
|
|
4
|
|
1360
|
use HiD::Server::Loader; |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
3093
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has auto_refresh => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => 'Bool', |
|
32
|
|
|
|
|
|
|
traits => [ 'Getopt' ], |
|
33
|
|
|
|
|
|
|
cmd_aliases => [ qw/ auto A / ], |
|
34
|
|
|
|
|
|
|
documentation => 'auto re-publish when source changes, Default=False', |
|
35
|
|
|
|
|
|
|
lazy => 1, |
|
36
|
|
|
|
|
|
|
default => 0, |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has clean => ( |
|
41
|
|
|
|
|
|
|
is => 'ro' , |
|
42
|
|
|
|
|
|
|
isa => 'Bool' , |
|
43
|
|
|
|
|
|
|
cmd_aliases => 'C' , |
|
44
|
|
|
|
|
|
|
traits => [ 'Getopt' ] , |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has debug => ( |
|
49
|
|
|
|
|
|
|
is => 'ro' , |
|
50
|
|
|
|
|
|
|
isa => 'Bool' , |
|
51
|
|
|
|
|
|
|
cmd_aliases => 'd' , |
|
52
|
|
|
|
|
|
|
traits => [ 'Getopt' ] , |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has port => ( |
|
57
|
|
|
|
|
|
|
is => 'ro' , |
|
58
|
|
|
|
|
|
|
isa => 'Int' , |
|
59
|
|
|
|
|
|
|
traits => [ 'Getopt' ] , |
|
60
|
|
|
|
|
|
|
cmd_aliases => 'p' , |
|
61
|
|
|
|
|
|
|
documentation => 'port to run the server on. Default=5000' , |
|
62
|
|
|
|
|
|
|
lazy => 1 , |
|
63
|
|
|
|
|
|
|
builder => '_build_port' , |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _build_port { |
|
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return $self->{port} if defined $self->{port}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $config = $self->config; |
|
72
|
0
|
|
0
|
|
|
|
return $self->config->{server_port} // 5000; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _run { |
|
76
|
0
|
|
|
0
|
|
|
my( $self , $opts , $args ) = @_; |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $config = $self->config; |
|
79
|
0
|
0
|
|
|
|
|
if ( $self->clean ) { |
|
80
|
0
|
|
|
|
|
|
$config->{clean_destination} = 1; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ( $self->publish_drafts ){ |
|
84
|
0
|
|
|
|
|
|
$config->{publish_drafts} = 1; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $app = HiD::Server->new( |
|
88
|
0
|
|
0
|
|
|
|
error_pages => ($config->{error_pages} || {} ), |
|
89
|
|
|
|
|
|
|
root => $self->destination, |
|
90
|
|
|
|
|
|
|
)->to_app; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if ( $self->debug ) { |
|
93
|
0
|
0
|
|
|
|
|
if ( try_load_class( 'Plack::Middleware::DebugLogging' )) { |
|
94
|
|
|
|
|
|
|
$app = builder { |
|
95
|
0
|
|
|
0
|
|
|
enable_if { $ENV{PLACK_ENV} eq 'development' } 'DebugLogging'; |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$app; |
|
97
|
0
|
|
|
|
|
|
}; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
else { |
|
100
|
0
|
|
|
|
|
|
print STDERR "*** Plack::Middleware::DebugLogging required for debug logging.\n"; |
|
101
|
0
|
|
|
|
|
|
print STDERR "*** Continuing with normal logging.\n"; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $runner = Plack::Runner->new; |
|
106
|
0
|
|
|
|
|
|
my %args = ( '-p' => $self->port ); |
|
107
|
0
|
|
|
|
|
|
$runner->parse_options(%args); |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# auto refresh |
|
110
|
0
|
0
|
|
|
|
|
if ( $self->auto_refresh ) { |
|
111
|
0
|
|
|
|
|
|
my @dirs = map { $self->hid->get_config($_) } qw/ include_dir layout_dir posts_dir /; |
|
|
0
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
for my $dir (qw/pages regular_files/) { |
|
114
|
0
|
|
|
|
|
|
push @dirs, map { $_->input_filename } @{ $self->hid->$dir }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# FIXME wish there was a better way to override stuff in Plack::Runner. >_< |
|
118
|
0
|
|
|
|
|
|
$runner->{server} = '+HiD::Server::Handler'; |
|
119
|
0
|
|
|
|
|
|
$runner->{loader} = '+HiD::Server::Loader'; |
|
120
|
0
|
|
|
|
|
|
$runner->loader->watch(@dirs); |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
push @{$runner->{options}} , ( hid => $self ); |
|
|
0
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# no need to explicitly ->publish() here, as that will happen inside |
|
125
|
|
|
|
|
|
|
# HiD::Server::Loader, in the child, after the fork. |
|
126
|
|
|
|
|
|
|
} |
|
127
|
0
|
|
|
|
|
|
else { $self->publish() } |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$runner->run($app); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
133
|
|
|
|
|
|
|
1; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=pod |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=encoding UTF-8 |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 NAME |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
HiD::App::Command::server - HiD 'server' subcmd - start up a Plack-based web server for your site |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$ ../bin/hid server |
|
148
|
|
|
|
|
|
|
HTTP::Server::PSGI: Accepting connections at http://0:5000/ |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Start a Plack-based web server that serves your C<destination> directory. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 auto_refresh |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Automatically refresh result when source file/dir changed, just likey jekyll |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Note that setting this will also clean out the destination directory whenever |
|
161
|
|
|
|
|
|
|
a watched file changes. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 clean |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Remove any existing site directory prior to the publication run |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 debug |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Emit debug-style logging for requests |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 port |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Port number to bind. Defaults to 5000. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
See L<HiD::App::Command> for additional command line options supported by all |
|
178
|
|
|
|
|
|
|
sub commands. |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 VERSION |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
version 1.991 |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
John SJ Anderson <genehack@genehack.org> |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This software is copyright (c) 2015 by John SJ Anderson. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
193
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |