Wouldn't it be a lot cleaner to make Resource#evaluate idempotent?  I would
tend do do something like:

diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index e34f284..6c217f7 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -64,14 +64,16 @@ class Puppet::Parser::Resource < Puppet::Resource

   # Retrieve the associated definition and evaluate it.
   def evaluate
-    @evaluated = true
-    if klass = resource_type and ! builtin_type?
-      finish
-      return klass.evaluate_code(self)
+    if evaluated?
+      #nothing to do
     elsif builtin?
       devfail "Cannot evaluate a builtin type (#{type})"
+    elsif klass = resource_type
+      @evaluated = true
+      finish
+      klass.evaluate_code(self)
     else
-      self.fail "Cannot find definition #{type}"
+      fail "Cannot find definition #{type}"
     end
   end

But it could be something as simple as:

diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index e34f284..c007d4d 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -64,6 +64,7 @@ class Puppet::Parser::Resource < Puppet::Resource

   # Retrieve the associated definition and evaluate it.
   def evaluate
+    return if evaluated?
     @evaluated = true
     if klass = resource_type and ! builtin_type?
       finish

My concern is that by handling it out of band we're fighting one set of
non-obvious side effects (evaluating resources can cause others to be
evaluated) by introducing another (fortran like business with flag variables
and nexting in a loop, etc.) and that makes the code more brittle than it
needs to be.

Did you consider this alternative?  If so, why was it rejected or if not,
would you consider it?

-- M
-----------------------------------------------------------
The power of accurate observation is
commonly called cynicism by those
who have not got it.  ~George Bernard Shaw
------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to