Slave.pm 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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%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\n", $_, $self->{meta}->{$_}
  23. foreach keys %{$self->{meta}};
  24. return join "", @head;
  25. }
  26. sub body {
  27. my $self = shift;
  28. my @source;
  29. push @source, $_->{line} . "\n" foreach @{$self->{steps}};
  30. return join "", @source;
  31. }
  32. sub warnings {
  33. my $self = shift;
  34. my @warnings;
  35. foreach my $step (@{$self->{steps}}) {
  36. push @warnings, $_ foreach @{$step->{warnings}};
  37. }
  38. my $warnings = "";
  39. if (@warnings) {
  40. $warnings .= "---\n# SUGAR-TRAIL WARNINGS #\n\n";
  41. foreach (@warnings) {
  42. $warnings .= "> warning: $_\n";
  43. }
  44. $warnings .= "---\n\n";
  45. }
  46. return $warnings;
  47. }
  48. 1;