|
@@ -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;
|