Przeglądaj źródła

Finished condition processing, first run

Alois Mahdal (@azzgoat) 12 lat temu
rodzic
commit
f0c8bffef8
2 zmienionych plików z 16 dodań i 16 usunięć
  1. 15
    15
      lib/SugarTrail/Template/Master.pm
  2. 1
    1
      t/data/strepo/release/rc.stm

+ 15
- 15
lib/SugarTrail/Template/Master.pm Wyświetl plik

@@ -9,6 +9,7 @@ use strict;
9 9
 use warnings;
10 10
 use Carp;
11 11
 use SugarTrail::Template::Slave;
12
+use SugarTrail::Template::Condition;
12 13
 
13 14
 sub new {
14 15
     my $class = shift;
@@ -43,9 +44,15 @@ sub _parse_body {
43 44
     $self->{steps} = [];
44 45
     foreach (split "\n", $self->{body}) {
45 46
         chomp; s/ *$//;
46
-        my ($line, $cond) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
47
+        my @conds;
48
+        my ($line, $cond_block) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
47 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 57
     return scalar @{ $self->{steps} };
51 58
 }
@@ -58,13 +65,13 @@ sub generate_slave {
58 65
 
59 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 77
     $slave->{meta}->{'Stm'} = $self->{stm};
@@ -75,13 +82,6 @@ sub generate_slave {
75 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 85
 # skel: returns time (might be useful in absence of VCS)
86 86
 sub get_current_revision {
87 87
     return time;

+ 1
- 1
t/data/strepo/release/rc.stm Wyświetl plik

@@ -15,6 +15,6 @@ This is the release client protocol.  Here the body starts...
15 15
     > result is OK
16 16
 3. Some XP thing        {os==wxx}
17 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 20
 Some final comments.