|
@@ -1,9 +1,9 @@
|
1
|
1
|
package SugarTrail::Template::Master;
|
2
|
2
|
# Master template holder
|
3
|
3
|
# new()
|
4
|
|
-# parse_headers()
|
5
|
|
-
|
6
|
|
-
|
|
4
|
+# parse()
|
|
5
|
+# _parse_headers()
|
|
6
|
+# _parse_body()
|
7
|
7
|
|
8
|
8
|
use strict;
|
9
|
9
|
use warnings;
|
|
@@ -18,38 +18,35 @@ sub new {
|
18
|
18
|
return bless $self, $class;
|
19
|
19
|
}
|
20
|
20
|
|
21
|
|
-sub parse_headers {
|
|
21
|
+sub parse {
|
22
|
22
|
my $self = shift;
|
23
|
|
-
|
24
|
23
|
my ($head, $body) = split "\n\n", $self->{text}, 2;
|
25
|
|
-
|
26
|
|
- my @lines = split "\n", $head;
|
27
|
|
-
|
28
|
24
|
$self->{head} = $head;
|
29
|
25
|
$self->{body} = $body;
|
|
26
|
+ return (
|
|
27
|
+ $self->_parse_headers(),
|
|
28
|
+ $self->_parse_body()
|
|
29
|
+ );
|
|
30
|
+}
|
30
|
31
|
|
31
|
|
- foreach (@lines) {
|
|
32
|
+sub _parse_headers {
|
|
33
|
+ my $self = shift;
|
|
34
|
+ foreach (split "\n", $self->{head}) {
|
32
|
35
|
my ($n, $v) = split ": ", $_, 2;
|
33
|
36
|
$self->{meta}->{$n} = $v;
|
34
|
37
|
}
|
35
|
|
-
|
36
|
38
|
return scalar keys %{ $self->{meta} };
|
37
|
39
|
}
|
38
|
40
|
|
39
|
|
-sub parse_body {
|
|
41
|
+sub _parse_body {
|
40
|
42
|
my $self = shift;
|
41
|
|
- my @lines = split "\n", $self->{body};
|
42
|
|
-
|
43
|
43
|
$self->{steps} = [];
|
44
|
|
-
|
45
|
|
- foreach (@lines) {
|
46
|
|
- chomp;
|
47
|
|
- s/ *$//;
|
|
44
|
+ foreach (split "\n", $self->{body}) {
|
|
45
|
+ chomp; s/ *$//;
|
48
|
46
|
my ($line, $cond) = $_ =~ m/^(.*?)(\{(.*)\})?$/;
|
49
|
47
|
$line =~ s/ *$//;
|
50
|
48
|
push @{ $self->{steps} }, { line => $line, cond => $cond };
|
51
|
49
|
}
|
52
|
|
-
|
53
|
50
|
return scalar @{ $self->{steps} };
|
54
|
51
|
}
|
55
|
52
|
|