Browse Source

Finished condition processing, first run

Alois Mahdal (@azzgoat) 12 years ago
parent
commit
f0c8bffef8
2 changed files with 16 additions and 16 deletions
  1. 15
    15
      lib/SugarTrail/Template/Master.pm
  2. 1
    1
      t/data/strepo/release/rc.stm

+ 15
- 15
lib/SugarTrail/Template/Master.pm View File

9
 use warnings;
9
 use warnings;
10
 use Carp;
10
 use Carp;
11
 use SugarTrail::Template::Slave;
11
 use SugarTrail::Template::Slave;
12
+use SugarTrail::Template::Condition;
12
 
13
 
13
 sub new {
14
 sub new {
14
     my $class = shift;
15
     my $class = shift;
43
     $self->{steps} = [];
44
     $self->{steps} = [];
44
     foreach (split "\n", $self->{body}) {
45
     foreach (split "\n", $self->{body}) {
45
         chomp; s/ *$//;
46
         chomp; s/ *$//;
46
-        my ($line, $cond) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
47
+        my @conds;
48
+        my ($line, $cond_block) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
47
         $line =~ s/ *$//;
49
         $line =~ s/ *$//;
48
-        push @{ $self->{steps} }, { line => $line, cond => $cond };
50
+        if ($cond_block) {
51
+            $cond_block =~ s/\}$//;
52
+            $cond_block =~ s/^\{//;
53
+            @conds = split m/\s*;\s*/, $cond_block;
54
+        }
55
+        push @{ $self->{steps} }, { line => $line, conds => \@conds };
49
     }
56
     }
50
     return scalar @{ $self->{steps} };
57
     return scalar @{ $self->{steps} };
51
 }
58
 }
58
 
65
 
59
     my @lines;
66
     my @lines;
60
 
67
 
61
-    STEP: foreach (@{ $self->{steps} }) {
62
-        unless ($_->{cond}) {
63
-            push @lines, $_->{line};
64
-            next STEP;
65
-        } else {
66
-            push @lines, $_->{line} if &matches($_->{cond}, $args);
68
+    STEP: foreach my $step (@{ $self->{steps} }) {
69
+        my $accept = 1;
70
+        COND: foreach my $condstr (@{ $step->{conds} }) {
71
+            my $c = SugarTrail::Template::Condition->new($condstr);
72
+            unless ($c->match($args)) { $accept = 0; last COND; }
67
         }
73
         }
74
+        push @lines, $step->{line} if $accept;
68
     }
75
     }
69
 
76
 
70
     $slave->{meta}->{'Stm'} = $self->{stm};
77
     $slave->{meta}->{'Stm'} = $self->{stm};
75
     return $slave;
82
     return $slave;
76
 }
83
 }
77
 
84
 
78
-# skel: matches if cond has m
79
-sub matches {
80
-    my $cond = shift;
81
-    my $args = shift;
82
-    $cond =~ m/m/;
83
-}
84
-
85
 # skel: returns time (might be useful in absence of VCS)
85
 # skel: returns time (might be useful in absence of VCS)
86
 sub get_current_revision {
86
 sub get_current_revision {
87
     return time;
87
     return time;

+ 1
- 1
t/data/strepo/release/rc.stm View File

15
     > result is OK
15
     > result is OK
16
 3. Some XP thing        {os==wxx}
16
 3. Some XP thing        {os==wxx}
17
 3. Some Win7 thing      {os=~w7*}
17
 3. Some Win7 thing      {os=~w7*}
18
-4. Some amd64 thing     {arch==amd64}
18
+4. Some amd64 thing     {arch==amd64;proto==pop3}
19
 
19
 
20
 Some final comments.
20
 Some final comments.