commit 5da1960cb46be0feaa153f365256dbf0dd7967ef
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Mon Nov 29 20:50:03 2010 +0100

    [evol] Task DSL: rework to use the same Task objet for the same task (in order to have a proper count of tasks and be able to transport information easily through steps)

diff --git a/bin/test_client b/bin/test_client
index c347fa0..2b9e2cc 100755
--- a/bin/test_client
+++ b/bin/test_client
@@ -36,9 +36,6 @@ module CyborgHood
       include BotNet
 
       def start_work
-        # to test the closure through the inner instance_eval calls
-        toto = true
-
         task "compare stuff" do
           ask "MapMaker", :info1, "/_cyborg_"
           ask "Librarian", :info2, "/_cyborg_"
@@ -48,6 +45,7 @@ module CyborgHood
             puts "PLOUF"
             pp errors
             pp results
+            stop_bot :at_once
           end
           on_success do
             puts "OK"
@@ -59,9 +57,9 @@ module CyborgHood
             on_success do
               puts "OK compare stuff"
             end
-          end
-          on_error do
-            stop_bot :at_once
+            on_error do
+              stop_bot :at_once
+            end
           end
         end
 
diff --git a/lib/cyborghood/cyborg/dsl.rb b/lib/cyborghood/cyborg/dsl.rb
index d8c1856..910cddd 100644
--- a/lib/cyborghood/cyborg/dsl.rb
+++ b/lib/cyborghood/cyborg/dsl.rb
@@ -23,22 +23,8 @@ require 'set'
 module CyborgHood
   module DSL
     class BaseDSL < ActiveSupport::BasicObject
-      def initialize(&block)
-        _load_block(&block)
-        _start_dsl
-      end
-
       reveal :class
       reveal :logger
-
-      protected
-
-      def _load_block(&block)
-        self.instance_eval(&block)
-      end
-
-      def _start_dsl
-      end
     end
 
     class Task < BaseDSL
@@ -50,32 +36,21 @@ module CyborgHood
         @@task_wip == 0
       end
 
-      def initialize(bot, name = nil, previous_step_data = {}, &block)
+      def initialize(bot, name = nil, &block)
         @bot = bot
         @name = name
 
         @@task_wip += 1
 
-        @errors = (previous_step_data[:errors] || {}).freeze
-        @results = (previous_step_data[:results] || {}).freeze
-
-        @dsl_runing = false
-        @subtasks = []
-        @cancel_on_start_error = false
-        @cancel_run = false
-
-        @error_cb = nil
-        @success_cb = nil
+        @errors = {}.freeze
+        @results = {}.freeze
 
         @notification_name = "task/#{@name}"
 
-        begin
-          super(&block)
-        rescue
-          logger.error "Task '#{@name}': error in DSL: " + $!.to_s
-          logger.debug $!.backtrace.join("\n")
-          @cancel_run = true
-        end
+        _start_dsl &block
+      end
+
+      def run_dsl
       end
 
       # may return a Hash of results
@@ -264,24 +239,24 @@ module CyborgHood
         # avoid race: no subtask will be run in this task now
         @dsl_runing = false
 
-        next_step_data = {
-          :errors => {},
-          :results => {}
-        }
-
+        # compute step result
+        @errors = {}
+        @results = {}
         @subtasks.each do |subtask|
-          next_step_data[:errors][subtask.name] = subtask.errors unless subtask.errors.empty?
-          next_step_data[:results].merge!(subtask.results)
+          @errors[subtask.name] = subtask.errors unless subtask.errors.empty?
+          @results.merge!(subtask.results)
         end
+        @errors.freeze
+        @result.freeze
 
-        cb = next_step_data[:errors].empty? ? @success_cb : @error_cb
+        # next step
+        cb = @errors.empty? ? @success_cb : @error_cb
         if cb
-          self.class.new(@bot, @name, next_step_data, &cb)
+          _start_dsl(&cb)
         else
-          logger.debug "Task '#{@name}': finished"
+          @@task_wip -= 1
+          logger.debug "Task '#{@name}': finished (#{@@task_wip} remaining)"
         end
-
-        @@task_wip -= 1
       end
 
       def _notification_criterias_match(msg, criterias)
@@ -296,8 +271,20 @@ module CyborgHood
         true
       end
 
-      def _start_dsl
-        return false if @cancel_run
+      def _start_dsl(&block)
+        @dsl_runing = false
+        @subtasks = []
+        @cancel_on_start_error = false
+        @error_cb = nil
+        @success_cb = nil
+
+        begin
+          instance_eval(&block)
+        rescue
+          logger.error "Task '#{@name}': error in DSL: " + $!.to_s
+          logger.debug $!.backtrace.join("\n")
+          return
+        end
 
         logger.debug "Task '#{@name}': begining step"
 
