STM.pm 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. # skel: matches if cond has m
  41. sub matches {
  42. my $cond = shift;
  43. my $args = shift;
  44. $cond =~ m/m/;
  45. }
  46. # skel: returns time (might be useful in absence of VCS)
  47. sub get_current_revision {
  48. return time;
  49. }
  50. 1;