# File lib/hiera/backend.rb, line 245
      def lookup(key, default, scope, order_override, resolution_type, context = {:recurse_guard => nil})
        @backends ||= {}
        answer = nil

        # order_override is kept as an explicit argument for backwards compatibility, but should be specified
        # in the context for internal handling.
        context ||= {}
        order_override ||= context[:order_override]
        context[:order_override] ||= order_override

        strategy = resolution_type.is_a?(Hash) ? :hash : resolution_type

        segments = Util.split_key(key) { |problem| ArgumentError.new("#{problem} in key: #{key}") }
        subsegments = nil
        if segments.size > 1
          unless strategy.nil? || strategy == :priority
            raise ArgumentError, "Resolution type :#{strategy} is illegal when accessing values using dotted keys. Offending key was '#{key}'"
          end
          subsegments = segments.drop(1)
        end

        found = false
        Config[:backends].each do |backend|
          backend_constant = "#{backend.capitalize}_backend"
          if constants.include?(backend_constant) || constants.include?(backend_constant.to_sym)
            backend = (@backends[backend] ||= find_backend(backend_constant))
            found_in_backend = false
            new_answer = catch(:no_such_key) do
              if subsegments.nil? 
                value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
              elsif backend.respond_to?(:lookup_with_segments)
                value = backend.lookup_with_segments(segments, scope, order_override, resolution_type, context)
              else
                value = backend.lookup(segments[0], scope, order_override, resolution_type, context)
                value = qualified_lookup(subsegments, value, key) unless subsegments.nil?
              end
              found_in_backend = true
              value
            end
            next unless found_in_backend
            found = true

            case strategy
            when :array
              raise Exception, "Hiera type mismatch for key '#{key}': expected Array and got #{new_answer.class}" unless new_answer.kind_of? Array or new_answer.kind_of? String
              answer ||= []
              answer << new_answer
            when :hash
              raise Exception, "Hiera type mismatch for key '#{key}': expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
              answer ||= {}
              answer = merge_answer(new_answer, answer, resolution_type)
            else
              answer = new_answer
              break
            end
          end
        end

        answer = resolve_answer(answer, strategy) unless answer.nil?
        answer = parse_string(default, scope, {}, context) if !found && default.is_a?(String)

        return default if !found && answer.nil?
        return answer
      end