SugarTrail.pm 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package SugarTrail;
  2. use Dancer ':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 (params => scalar params);
  16. &helper::dmup (config => config);
  17. &helper::dmup (real_params => $params);
  18. my ($stpath, $query) = splat;
  19. my $format = $params->{__format} // 'plain';
  20. header('Content-Type' => (
  21. $format eq 'html' ? 'text/html' : 'text/plain'
  22. ));
  23. my $m = $r->load_master( source => "/$stpath.stm" )
  24. or return template 'not_found';
  25. my $s = $m->generate_slave($params);
  26. template 'st', {
  27. st_headers => $s->head(),
  28. content => $s->body(),
  29. warnings => $s->warnings()
  30. }, { layout => $format };
  31. };
  32. get '/' => sub {
  33. template 'index';
  34. };
  35. true;