package SugarTrail; use Dancer2 ':syntax'; use strict; use warnings; use SugarTrail::Repo; use Template; use helper; our $VERSION = '0.1'; my $r = SugarTrail::Repo->new( root => config->{repo_root} // "t/data/strepo", vcs => config->{repo_vcs} // "git" ); get qr|^/st/([^\?]*)(.*)$| => sub { my $params = request->params('query'); &helper::dmup (ENV => \%ENV); &helper::dmup (real_params => $params); my ($stpath, $query) = splat; my $format = $params->{__format} // 'plain'; header('Content-Type' => ( $format eq 'html' ? 'text/html' : 'text/plain' )); my $m = $r->load_master( source => "/$stpath.stm" ) or return template 'not_found'; my $s = $m->generate_slave($params); &helper::dmup(m=>$m); &helper::dmup(s=>$s); my $w = $s->warnings(); &helper::dmup(w=>$w); template $format, { s_head => $s->head(), s_body => $s->body(), s_warnings => $s->warnings(), m_Name => $m->{meta}->{Name}, s_Master => $s->{meta}->{Master}, s_MasterRevision => $s->{meta}->{'Master Revision'} }, { layout => $format }; }; get '/' => sub { template 'index'; }; true;