Browse Source

Added auto-parsing

Alois Mahdal 12 years ago
parent
commit
d3b2c04545
2 changed files with 5 additions and 5 deletions
  1. 5
    2
      lib/SugarTrail/Template/Master.pm
  2. 0
    3
      t/Slave.t

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

16
     my $args = { @_ };
16
     my $args = { @_ };
17
     my $self = {};
17
     my $self = {};
18
     $self->{args} = $args;
18
     $self->{args} = $args;
19
+    $self->{parsed} = 0;
19
     return bless $self, $class;
20
     return bless $self, $class;
20
 }
21
 }
21
 
22
 
24
     my ($head, $body) = split "\n\n", $self->{text}, 2;
25
     my ($head, $body) = split "\n\n", $self->{text}, 2;
25
     $self->{head} = $head;
26
     $self->{head} = $head;
26
     $self->{body} = $body;
27
     $self->{body} = $body;
27
-    return (
28
+    my @counts = (
28
         $self->_parse_headers(),
29
         $self->_parse_headers(),
29
         $self->_parse_body()
30
         $self->_parse_body()
30
     );
31
     );
32
+    $self->{parsed}++;
33
+    return @counts;
31
 }
34
 }
32
 
35
 
33
 sub _parse_headers {
36
 sub _parse_headers {
60
 sub generate_slave {
63
 sub generate_slave {
61
     my $self = shift;
64
     my $self = shift;
62
     my $args = shift;
65
     my $args = shift;
66
+    $self->parse() unless $self->{parsed};
63
 
67
 
64
     #create an "empty" slave
68
     #create an "empty" slave
65
     my $slave = SugarTrail::Template::Slave->new($args);
69
     my $slave = SugarTrail::Template::Slave->new($args);
66
 
70
 
67
     my @slave_steps;
71
     my @slave_steps;
68
-
69
     STEP: foreach my $master_step (@{ $self->{steps} }) {
72
     STEP: foreach my $master_step (@{ $self->{steps} }) {
70
         my $accept = 1;     # accept by default
73
         my $accept = 1;     # accept by default
71
         my $slave_step = {
74
         my $slave_step = {

+ 0
- 3
t/Slave.t View File

6
 
6
 
7
 my $repo = SugarTrail::Repo->new(root => './t/data/strepo', vcs => 'git');
7
 my $repo = SugarTrail::Repo->new(root => './t/data/strepo', vcs => 'git');
8
 
8
 
9
-
10
 my $m1 = $repo->load_stm(stm=>'/selftest/posititve/multiple_parameters.stm');
9
 my $m1 = $repo->load_stm(stm=>'/selftest/posititve/multiple_parameters.stm');
11
 ok($m1,             "multiple_parameters: master is true");
10
 ok($m1,             "multiple_parameters: master is true");
12
 
11
 
13
-$m1->parse();
14
-
15
 my $s1 = $m1->generate_slave({ proto => "imap", os => "w7a" });
12
 my $s1 = $m1->generate_slave({ proto => "imap", os => "w7a" });
16
 ok($s1,            "multiple_parameters: slave is true");
13
 ok($s1,            "multiple_parameters: slave is true");
17
 
14