module Roda::RodaPlugins::AutoloadHashBranches::ClassMethods

def autoload_hash_branch(namespace='', segment, file)

The given file should configure the hash branch specified.
Autoload the given file when there is request for the hash branch.
def autoload_hash_branch(namespace='', segment, file)
  segment = "/#{segment}"
  file = File.expand_path(file)
  opts[:autoload_hash_branch_files] << file
  routes = opts[:hash_branches][namespace] ||= {}
  meth = routes[segment] = define_roda_method(routes[segment] || "hash_branch_#{namespace}_#{segment}", 1) do |r|
    loc = method(routes[segment]).source_location
    require file
    # Avoid infinite loop in case method is not overridden
    if method(meth).source_location != loc
      send(meth, r)
    end
  end
  nil
end