Browse Source

Added parse_body()

Alois Mahdal (@azzgoat) 12 years ago
parent
commit
5b64ba3eb8
2 changed files with 19 additions and 0 deletions
  1. 16
    0
      lib/SugarTrail/STM.pm
  2. 3
    0
      t/Repo.t

+ 16
- 0
lib/SugarTrail/STM.pm View File

35
     return scalar keys %{ $self->{meta} };
35
     return scalar keys %{ $self->{meta} };
36
 }
36
 }
37
 
37
 
38
+sub parse_body {
39
+    my $self = shift;
40
+    my @lines = split "\n", $self->{body};
41
+
42
+    $self->{steps} = [];
43
+
44
+    foreach (@lines) {
45
+        chomp;
46
+        s/ *$//;
47
+        my ($line, $cond) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
48
+        $line =~ s/ *$//;
49
+        push @{ $self->{steps} }, { line => $line, cond => $cond };
50
+    }
51
+
52
+    return scalar @{ $self->{steps} };
53
+}
38
 
54
 
39
 1;
55
 1;

+ 3
- 0
t/Repo.t View File

15
 
15
 
16
 ok($stm->parse_headers(), "parse_headers() returns 6");
16
 ok($stm->parse_headers(), "parse_headers() returns 6");
17
 ok($stm->parse_headers(), "parse_headers() still returns 6");
17
 ok($stm->parse_headers(), "parse_headers() still returns 6");
18
+is($stm->parse_body(), 13, "parse_body() returns 13");
19
+is($stm->parse_body(), 13, "parse_body() still returns 13");
20
+
18
 &helper::dmupp(stm=>$stm);
21
 &helper::dmupp(stm=>$stm);
19
 
22
 
20
 done_testing();
23
 done_testing();