SugarTrail.pm 976B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. template 'st', {
  26. st_headers => $s->head(),
  27. content => $s->body(),
  28. warnings => $s->warnings()
  29. }, { layout => $format };
  30. };
  31. get '/' => sub {
  32. template 'index';
  33. };
  34. true;