# File lib/puppet/transaction.rb, line 58
 58:     def apply(resource)
 59:         begin
 60:             changes = resource.evaluate
 61:         rescue => detail
 62:             if Puppet[:trace]
 63:                 puts detail.backtrace
 64:             end
 65: 
 66:             resource.err "Failed to retrieve current state of resource: %s" % detail
 67: 
 68:             # Mark that it failed
 69:             @failures[resource] += 1
 70: 
 71:             # And then return
 72:             return []
 73:         end
 74: 
 75:         changes = [changes] unless changes.is_a?(Array)
 76: 
 77:         if changes.length > 0
 78:             @resourcemetrics[:out_of_sync] += 1
 79:         end
 80: 
 81:         return [] if changes.empty? or ! allow_processing?(resource, changes)
 82: 
 83:         resourceevents = apply_changes(resource, changes)
 84: 
 85:         # If there were changes and the resource isn't in noop mode...
 86:         unless changes.empty? or resource.noop
 87:             # Record when we last synced
 88:             resource.cache(:synced, Time.now)
 89: 
 90:             # Flush, if appropriate
 91:             if resource.respond_to?(:flush)
 92:                 resource.flush
 93:             end
 94: 
 95:             # And set a trigger for refreshing this resource if it's a
 96:             # self-refresher
 97:             if resource.self_refresh? and ! resource.deleting?
 98:                 # Create an edge with this resource as both the source and
 99:                 # target.  The triggering method treats these specially for
100:                 # logging.
101:                 events = resourceevents.collect { |e| e.name }
102:                 set_trigger(Puppet::Relationship.new(resource, resource, :callback => :refresh, :event => events))
103:             end
104:         end
105: 
106:         resourceevents
107:     end