dev mode
[scpubgit/SCS.git] / lib / SCSite / DevMode.pm
diff --git a/lib/SCSite/DevMode.pm b/lib/SCSite/DevMode.pm
new file mode 100644 (file)
index 0000000..cc5bf6a
--- /dev/null
@@ -0,0 +1,32 @@
+package SCSite::DevMode;
+
+use Plack::App::File;
+use Plack::Runner;
+use Moo::Role;
+
+has _static_handler => (is => 'lazy');
+
+sub _build__static_handler {
+  my ($self) = @_;
+  my $static_dir = $self->config->{static_dir};
+  Plack::App::File->new(root => $static_dir)->to_app;
+}
+
+around dispatch_request => sub {
+  my ($orig, $self) = (shift, shift);
+  no warnings::illegalproto;
+  (
+    sub (/static/...) { $self->_static_handler },
+    $self->$orig(@_)
+  )
+};
+
+sub _run_dev_server {
+  my ($self, @args) = @_;
+  my $r = Plack::Runner->new(server => 'Starman', app => $self->to_psgi_app);
+  $r->parse_options(@args);
+  $r->set_options(argv => \@args);
+  $r->run;
+}
+
+1;