Przeglądaj źródła

Revamped condition evaluation

Now warnings from condition evaluation are passed down to Slave
Alois Mahdal 11 lat temu
rodzic
commit
869b55fc4a
1 zmienionych plików z 18 dodań i 2 usunięć
  1. 18
    2
      lib/SugarTrail/Template/Master.pm

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

67
 
67
 
68
     STEP: foreach my $master_step (@{ $self->{steps} }) {
68
     STEP: foreach my $master_step (@{ $self->{steps} }) {
69
         my $accept = 1;
69
         my $accept = 1;
70
+        my $slave_step = {
71
+            line        => $master_step->{line},
72
+            warnings    => []
73
+        };
70
         COND: foreach my $condstr (@{ $master_step->{conds} }) {
74
         COND: foreach my $condstr (@{ $master_step->{conds} }) {
71
             my $c = SugarTrail::Template::Condition->new($condstr);
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
     $slave->{meta}->{'Stm'} = $self->{stm};
93
     $slave->{meta}->{'Stm'} = $self->{stm};