Browse Source

Added skeleton for basic STS generation

Alois Mahdal (@azzgoat) 11 years ago
parent
commit
83ed591407
2 changed files with 26 additions and 0 deletions
  1. 22
    0
      lib/SugarTrail/STM.pm
  2. 4
    0
      t/Repo.t

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

@@ -8,6 +8,7 @@ package SugarTrail::STM;
8 8
 use strict;
9 9
 use warnings;
10 10
 use Carp;
11
+use SugarTrail::STS;
11 12
 
12 13
 sub new {
13 14
     my $class = shift;
@@ -52,6 +53,27 @@ sub parse_body {
52 53
     return scalar @{ $self->{steps} };
53 54
 }
54 55
 
56
+sub generate_sts {
57
+    my $self = shift;
58
+    my $args = shift;
59
+
60
+    my $sts = SugarTrail::STS->new($args);
61
+
62
+    my @lines;
63
+
64
+    STEP: foreach (@{ $self->{steps} }) {
65
+        unless ($_->{cond}) {
66
+            push @lines, $_->{line};
67
+            next STEP;
68
+        } else {
69
+            push @lines, $_->{line} if &matches($_->{cond}, $args);
70
+        }
71
+    }
72
+
73
+    $sts->{lines} = \@lines;
74
+    return $sts;
75
+}
76
+
55 77
 # skel: matches if cond has m
56 78
 sub matches {
57 79
     my $cond = shift;

+ 4
- 0
t/Repo.t View File

@@ -19,4 +19,8 @@ is($stm->parse_body(), 13, "parse_body() still returns 13");
19 19
 
20 20
 &helper::dmupp(stm=>$stm);
21 21
 
22
+my $sts = $stm->generate_sts({ proto => "imap" });
23
+ok($sts,            "sts is true");
24
+&helper::dmupp(sts=>$sts);
25
+
22 26
 done_testing();