1. my class Pod::Block {
  2. has %.config;
  3. has @.contents;
  4. submethod BUILD(:%!config, :@!contents --> Nil) {}
  5. sub pod-gist(Pod::Block $pod, $level = 0) {
  6. my $leading = ' ' x $level;
  7. my %confs;
  8. my @chunks;
  9. for <config name level caption type> {
  10. my $thing = $pod.?"$_"();
  11. if $thing {
  12. %confs{$_} = nqp::istype($thing,Iterable)
  13. ?? $thing.perl
  14. !! $thing.Str;
  15. }
  16. }
  17. @chunks = $leading, $pod.^name, (%confs.perl if %confs), "\n";
  18. for $pod.contents.flat -> $c {
  19. if nqp::istype($c,Pod::Block) {
  20. @chunks.push: pod-gist($c, $level + 2);
  21. }
  22. elsif nqp::istype($c,Positional) {
  23. @chunks.append: $c>>.Str.perl.indent($level + 2), "\n";
  24. }
  25. else {
  26. @chunks.append: $c.Str.indent($level + 2), "\n";
  27. }
  28. }
  29. @chunks.join;
  30. }
  31. multi method gist(Pod::Block:D:) {
  32. pod-gist(self)
  33. }
  34. }
  35. my class Pod::Block::Para is Pod::Block {
  36. }
  37. my class Pod::Block::Named is Pod::Block {
  38. has $.name;
  39. }
  40. my class Pod::Block::Comment is Pod::Block { }
  41. my class Pod::Block::Code is Pod::Block {
  42. has @.allowed;
  43. }
  44. my class Pod::Block::Declarator is Pod::Block {
  45. has $.WHEREFORE;
  46. has @!leading;
  47. has @!trailing;
  48. submethod BUILD(:@!leading, :@!trailing --> Nil) {}
  49. method set_docee($d) {
  50. $!WHEREFORE = $d
  51. }
  52. method Str {
  53. @.contents.join('')
  54. }
  55. multi method gist(Pod::Block::Declarator:D:) {
  56. @.contents.join('')
  57. }
  58. method contents {
  59. if @!leading && @!trailing {
  60. [ $.leading ~ "\n" ~ $.trailing ]
  61. } elsif @!leading {
  62. [ $.leading ]
  63. } elsif @!trailing {
  64. [ $.trailing ]
  65. } else {
  66. []
  67. }
  68. }
  69. method leading { @!leading ?? @!leading.join(' ') !! Nil }
  70. method trailing { @!trailing ?? @!trailing.join(' ') !! Nil }
  71. method _add_leading($addition) {
  72. @!leading.push: ~$addition;
  73. }
  74. method _add_trailing($addition) {
  75. @!trailing.push: ~$addition;
  76. }
  77. }
  78. my class Pod::Block::Table is Pod::Block {
  79. has $.caption;
  80. has @.headers; # optional, may be empty
  81. }
  82. my class Pod::FormattingCode is Pod::Block {
  83. has $.type;
  84. has @.meta;
  85. }
  86. my class Pod::Heading is Pod::Block {
  87. has $.level;
  88. }
  89. my class Pod::Item is Pod::Block {
  90. has $.level;
  91. }
  92. class Pod::Config {
  93. has $.type;
  94. has %.config;
  95. }
  96. # for passing raw instructions to specific backends
  97. class Pod::Raw {
  98. has $.target;
  99. has @.contents;
  100. }