add checkall dev command to look for botched pages
[scpubgit/SCS.git] / lib / SCSite / DevMode.pm
CommitLineData
99cee940 1package SCSite::DevMode;
2
3use Plack::App::File;
4use Plack::Runner;
9d4b4027 5use Try::Tiny;
99cee940 6use Moo::Role;
7
8has _static_handler => (is => 'lazy');
9
10sub _build__static_handler {
11 my ($self) = @_;
12 my $static_dir = $self->config->{static_dir};
7f2b58ea 13 Plack::App::File->new(root => $static_dir);
99cee940 14}
15
16around dispatch_request => sub {
17 my ($orig, $self) = (shift, shift);
18 no warnings::illegalproto;
19 (
20 sub (/static/...) { $self->_static_handler },
f08b95b6 21 sub (/favicon + .ico) { $self->_static_handler },
99cee940 22 $self->$orig(@_)
23 )
24};
25
26sub _run_dev_server {
27 my ($self, @args) = @_;
28 my $r = Plack::Runner->new(server => 'Starman', app => $self->to_psgi_app);
29 $r->parse_options(@args);
30 $r->set_options(argv => \@args);
31 $r->run;
32}
33
9d4b4027 34sub _run_dev_checkall {
35 my ($self) = @_;
36 my $ps = $self->pages;
37 foreach my $path ($ps->all_paths) {
38 try {
39 $ps->get({ path => $path });
40 print "OK ${path}\n";
41 } catch {
42 print "ERROR ${path}\n";
43 print " $_";
44 };
45 }
46}
47
99cee940 481;