require "singleton"

module Apache
  class RubyRun
    include Singleton

    def handler(r)
      if r.finfo.mode == 0
        return NOT_FOUND
      end
      if r.allow_options & OPT_EXECCGI == 0
        r.log_reason("Options ExecCGI is off in this directory", r.filename)
        return FORBIDDEN
      end
      unless r.finfo.executable?
        r.log_reason("file permissions deny server execution", r.filename)
        return FORBIDDEN
      end
      r.setup_cgi_env
      Apache.chdir_file(r.filename)
      load(r.filename, true)
      return OK
    end
  end
end

