cc5bf6a1e612fda37fc59d9beef6b1ba4e59b606
[scpubgit/SCS.git] / lib / SCSite / DevMode.pm
1 package SCSite::DevMode;
2
3 use Plack::App::File;
4 use Plack::Runner;
5 use Moo::Role;
6
7 has _static_handler => (is => 'lazy');
8
9 sub _build__static_handler {
10   my ($self) = @_;
11   my $static_dir = $self->config->{static_dir};
12   Plack::App::File->new(root => $static_dir)->to_app;
13 }
14
15 around dispatch_request => sub {
16   my ($orig, $self) = (shift, shift);
17   no warnings::illegalproto;
18   (
19     sub (/static/...) { $self->_static_handler },
20     $self->$orig(@_)
21   )
22 };
23
24 sub _run_dev_server {
25   my ($self, @args) = @_;
26   my $r = Plack::Runner->new(server => 'Starman', app => $self->to_psgi_app);
27   $r->parse_options(@args);
28   $r->set_options(argv => \@args);
29   $r->run;
30 }
31
32 1;