Browse Source

Revamped condition evaluation

Now warnings from condition evaluation are passed down to Slave
Alois Mahdal 11 years ago
parent
commit
869b55fc4a
1 changed files with 18 additions and 2 deletions
  1. 18
    2
      lib/SugarTrail/Template/Master.pm

+ 18
- 2
lib/SugarTrail/Template/Master.pm View File

@@ -67,11 +67,27 @@ sub generate_slave {
67 67
 
68 68
     STEP: foreach my $master_step (@{ $self->{steps} }) {
69 69
         my $accept = 1;
70
+        my $slave_step = {
71
+            line        => $master_step->{line},
72
+            warnings    => []
73
+        };
70 74
         COND: foreach my $condstr (@{ $master_step->{conds} }) {
71 75
             my $c = SugarTrail::Template::Condition->new($condstr);
72
-            unless ($c->match($args)) { $accept = 0; last COND; }
76
+            my ($r, $w) = $c->match($args);
77
+
78
+            # if warnings, store them, prepare to accept and ignore result
79
+            if (scalar @$w) {
80
+                $accept = 1;
81
+                push @{$slave_step->{warnings}}, @$w;
82
+                next COND;
83
+            } else {
84
+                # point of no warnings -- refusal should be valid here
85
+                $accept = 0 unless $r;
86
+            }
73 87
         }
74
-        push @slave_steps, $master_step->{line} if $accept;
88
+
89
+        push @slave_steps, $slave_step
90
+            if ($accept || scalar @{$slave_step->{warnings}});
75 91
     }
76 92
 
77 93
     $slave->{meta}->{'Stm'} = $self->{stm};