Browse Source

Reduced empty data fields

Alois Mahdal 11 years ago
parent
commit
d73cd7dfcc
1 changed files with 26 additions and 19 deletions
  1. 26
    19
      lib/SugarTrail/Template/Master.pm

+ 26
- 19
lib/SugarTrail/Template/Master.pm View File

@@ -30,6 +30,7 @@ sub parse {
30 30
         $self->_parse_body()
31 31
     );
32 32
     $self->{parsed}++;
33
+    delete $self->{text};
33 34
     return @counts;
34 35
 }
35 36
 
@@ -39,6 +40,7 @@ sub _parse_headers {
39 40
         my ($n, $v) = split ": ", $_, 2;
40 41
         $self->{meta}->{$n} = $v;
41 42
     }
43
+    delete $self->{head};
42 44
     return scalar keys %{ $self->{meta} };
43 45
 }
44 46
 
@@ -55,8 +57,11 @@ sub _parse_body {
55 57
             $cond_block =~ s/^\{//;
56 58
             @conds = split m/\s*;\s*/, $cond_block;
57 59
         }
58
-        push @{ $self->{steps} }, { line => $line, conds => \@conds };
60
+        my $step = { line => $line };
61
+        $step->{conds} = \@conds if @conds;
62
+        push @{ $self->{steps} }, $step;
59 63
     }
64
+    delete $self->{body};
60 65
     return scalar @{ $self->{steps} };
61 66
 }
62 67
 
@@ -72,34 +77,36 @@ sub generate_slave {
72 77
         my $accept = 1;     # accept by default
73 78
         my $slave_step = {
74 79
             line        => $master_step->{line},
75
-            warnings    => []
76 80
         };
77 81
 
78 82
         # Test against each condition from the pre-parsed condblock.
79 83
         # *   refuse step only in case all conditions passed without
80 84
         #     warnings
81 85
         # *   in all other cases (fail, warning), accept
82
-        COND: foreach my $condstr (@{ $master_step->{conds} }) {
83
-            my $c = SugarTrail::Template::Condition->new($condstr);
84
-            unless ($c) {
85
-                $self->{error} = "condition error: $c->{error}";
86
-                return;
87
-            }
88
-            my ($r, $w) = $c->match($args);
89
-
90
-            # if warnings, store them, prepare to accept and ignore result
91
-            if (scalar @$w) {
92
-                $accept = 1;
93
-                push @{$slave_step->{warnings}}, @$w;
94
-                next COND;
95
-            } else {
96
-                # point of no warnings -- refusal should be valid here
97
-                $accept = 0 unless $r;
86
+        if ($master_step->{conds}) {
87
+            COND: foreach my $condstr (@{ $master_step->{conds} }) {
88
+                my $c = SugarTrail::Template::Condition->new($condstr);
89
+                unless ($c) {
90
+                    $self->{error} = "condition error: $c->{error}";
91
+                    return;
92
+                }
93
+                my ($r, $w) = $c->match($args);
94
+
95
+                # if warnings, store them, prepare to accept and ignore result
96
+                if (scalar @$w) {
97
+                    $accept = 1;
98
+                    push @{$slave_step->{warnings}}, @$w;
99
+                    next COND;
100
+                } else {
101
+                    # point of no warnings -- refusal should be valid here
102
+                    $accept = 0 unless $r;
103
+                }
98 104
             }
99 105
         }
100 106
 
101 107
         push @slave_steps, $slave_step
102
-            if ($accept || scalar @{$slave_step->{warnings}});
108
+            if ($accept || defined $slave_step->{warnings}
109
+                        && scalar @{$slave_step->{warnings}});
103 110
     }
104 111
 
105 112
     $slave->{meta}->{'Master'} = $self->{source};