Slave.pm 880B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return \@warnings;
  39. }
  40. 1;