12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package SugarTrail;
  2. use Dancer2 ':syntax';
  3. use strict;
  4. use warnings;
  5. use SugarTrail::Repo;
  6. use Template;
  7. use helper;
  8. our $VERSION = '0.1';
  9. my $r = SugarTrail::Repo->new(
  10. root => config->{repo_root} // "t/data/strepo",
  11. vcs => config->{repo_vcs} // "git"
  12. );
  13. get qr|^/st/([^\?]*)(.*)$| => sub {
  14. my $params = request->params('query');
  15. &helper::dmup (ENV => \%ENV);
  16. &helper::dmup (real_params => $params);
  17. my ($stpath, $query) = splat;
  18. my $format = $params->{__format} // 'plain';
  19. header('Content-Type' => (
  20. $format eq 'html' ? 'text/html' : 'text/plain'
  21. ));
  22. my $m = $r->load_master( source => "/$stpath.stm" )
  23. or return template 'not_found';
  24. my $s = $m->generate_slave($params);
  25. &helper::dmup(m=>$m);
  26. &helper::dmup(s=>$s);
  27. my $w = $s->warnings();
  28. &helper::dmup(w=>$w);
  29. template $format, {
  30. s_head => $s->head(),
  31. s_body => $s->body(),
  32. s_warnings => $s->warnings(),
  33. m_Name => $m->{meta}->{Name},
  34. s_Master => $s->{meta}->{Master},
  35. s_MasterRevision => $s->{meta}->{'Master Revision'}
  36. }, { layout => $format };
  37. };
  38. get '/' => sub {
  39. template 'index';
  40. };
  41. true;