Slave.pm 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package SugarTrail::Template::Slave;
  2. # STS holder
  3. # new()
  4. use strict;
  5. use warnings;
  6. use Carp;
  7. sub new {
  8. my $class = shift;
  9. my $args = shift;
  10. my $self = {};
  11. $self->{args} = $args;
  12. $self->{steps} = [];
  13. return bless $self, $class;
  14. }
  15. sub source {
  16. my $self = shift;
  17. return sprintf "%s\n\n%s%s", $self->head, $self->warnings, $self->body;
  18. }
  19. sub head {
  20. my $self = shift;
  21. my @head;
  22. push @head, sprintf "%s: %s", $_, $self->{meta}->{$_} foreach keys %{$self->{meta}};
  23. return join "\n", @head;
  24. }
  25. sub body {
  26. my $self = shift;
  27. my @source;
  28. push @source, $_->{line} foreach @{$self->{steps}};
  29. return join "\n", @source;
  30. }
  31. sub warnings {
  32. my $self = shift;
  33. my @warnings;
  34. foreach my $step (@{$self->{steps}}) {
  35. push @warnings, $_ foreach @{$step->{warnings}};
  36. }
  37. my $warnings;
  38. if (@warnings) {
  39. $warnings .= "---\n# SUGAR-TRAIL WARNINGS #\n\n";
  40. foreach (@warnings) {
  41. $warnings .= "> warning: $_\n";
  42. }
  43. $warnings .= "---\n\n";
  44. }
  45. return $warnings;
  46. }
  47. 1;