Hi, 

I have a question about eval and binding, with mod_ruby.
It is no problem to execute CGI program on command-line,
but an internal error happened when executing as mod_ruby script.

Here is the scripts.

viewloader.rb:
  .--------------------
  def output(filename, _binding=TOPLEVEL_BINDING)
    s = nil
    File.open(filename) do |file|
      s = file.read
    end
    s.untaint
    eval s, _binding
  end
  .--------------------


view.rb:
  .--------------------
  print "Hello #{username}!\n"
  .--------------------


logic.rbx:
  .--------------------
  #!/usr/bin/ruby
  
  require 'cgi'
  cgi = CGI.new
  print cgi.header
  
  require 'viewloader'
  username = 'Ruby'
  output('view.rb')   # I prefer this rather than
                      # output('view.rb', binding())
  .--------------------


result(command-line): -- No Problem.
  .====================
  $ ruby logic.rbx 
  (offline mode: enter name=value pairs on standard input)
  Content-Type: text/html
  
  Hello Ruby!
  .====================


result(apache error_log):  -- INTERNAL ERROR!
  .====================
  [Thu May  1 11:41:59 2003] [error] mod_ruby: error in ruby
  /home/httpd/html/sample/viewloader.rb:7:in `eval': (eval):1:
   undefined local variable or method `username' for #<Object:0x40b35c90>
   (NameError)
          from /home/httpd/html/sample/viewloader.rb:7:in `output'
          from /home/httpd/html/sample/logic.rbx:9
          from /usr/lib/ruby/1.6/apache/ruby-run.rb:63:in `load'
          from /usr/lib/ruby/1.6/apache/ruby-run.rb:63:in `handler'
          from ruby:0
  .====================

I don't know why the mod_ruby error happens.
Please give me an advice.

# I can succeed if using output('view.rb', binding)
# instead of output('view.rb') in logic.rbx,
# but I want to use the former.


--
regards
kwatch