STM.pm 950B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package SugarTrail::STM;
  2. # STM holder
  3. # new()
  4. # parse_headers()
  5. use strict;
  6. use warnings;
  7. use Carp;
  8. sub new {
  9. my $class = shift;
  10. my $args = { @_ };
  11. my $self = {};
  12. $self->{args} = $args;
  13. return bless $self, $class;
  14. }
  15. sub parse_headers {
  16. my $self = shift;
  17. my ($head, $body) = split "\n\n", $self->{text}, 2;
  18. my @lines = split "\n", $head;
  19. $self->{head} = $head;
  20. $self->{body} = $body;
  21. foreach (@lines) {
  22. my ($n, $v) = split ": ", $_, 2;
  23. $self->{meta}->{$n} = $v;
  24. }
  25. return scalar keys %{ $self->{meta} };
  26. }
  27. sub parse_body {
  28. my $self = shift;
  29. my @lines = split "\n", $self->{body};
  30. $self->{steps} = [];
  31. foreach (@lines) {
  32. chomp;
  33. s/ *$//;
  34. my ($line, $cond) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
  35. $line =~ s/ *$//;
  36. push @{ $self->{steps} }, { line => $line, cond => $cond };
  37. }
  38. return scalar @{ $self->{steps} };
  39. }
  40. 1;