Vars.pm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package Trog::Vars;
  2. use 5.040;
  3. use re '/aasx';
  4. use warnings FATAL => 'all';
  5. =head1 Trog::Vars
  6. Constants shared between the data model, the renderer and the routes.
  7. Nothing here is computed; it's all package variables so that callers can read
  8. them directly rather than paying for a function call on every request.
  9. =head2 VARIABLES
  10. =over 4
  11. =item %content_types
  12. Maps the short names used in templates and route definitions (html, json, ...)
  13. onto the Content-Type header they mean.
  14. =item %byct
  15. The reverse of %content_types, for going from a Content-Type back to the short
  16. name -- which is how the renderer picks which Trog::Renderer subclass handles a
  17. response.
  18. =item %cache_control
  19. Named Cache-Control policies. 'revalidate' for content which may have changed,
  20. 'nocache' for anything user specific, and 'static' for assets which are
  21. immutable once published.
  22. =back
  23. =cut
  24. our %content_types = (
  25. text => "text/plain",
  26. html => "text/html",
  27. json => "application/json",
  28. blob => "application/octet-stream",
  29. xml => "text/xml",
  30. xsl => "text/xsl",
  31. css => "text/css",
  32. rss => "application/rss+xml",
  33. email => "multipart/related",
  34. );
  35. our %byct = reverse %Trog::Vars::content_types;
  36. our %cache_control = (
  37. revalidate => "no-cache, max-age=0",
  38. nocache => "no-store",
  39. static => "public, max-age=604800, immutable",
  40. );
  41. # NOTE: the post schema and its validators used to be duplicated here as well
  42. # as in Trog::DataModule, and filter() had no callers at all. Both are gone --
  43. # a post's shape is now an OpenAPIv3 schema, see Trog::DataModule::schema_for().
  44. 1;