Procházet zdrojové kódy

Added auto-parsing

Alois Mahdal před 12 roky
rodič
revize
d3b2c04545
2 změnil soubory, kde provedl 5 přidání a 5 odebrání
  1. 5
    2
      lib/SugarTrail/Template/Master.pm
  2. 0
    3
      t/Slave.t

+ 5
- 2
lib/SugarTrail/Template/Master.pm Zobrazit soubor

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

+ 0
- 3
t/Slave.t Zobrazit soubor

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