SugarTrail.pm 984B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 $p = params();
  14. &helper::dmup (ENV => \%ENV);
  15. &helper::dmup (params => scalar params);
  16. &helper::dmup (config => config);
  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(scalar 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;