SugarTrail.pm 962B

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