ReSourcing Direct Domain procs when changed

I have an application server which I developed in 2001 using Tclhttpd. I was recently asked to add some new pages and update a few things (late 2005).

I'm using direct domains because I really like the way the form values are mapped into proc args. This makes handeling forms trivial. I also have my own home grown session/auth system since I didn't want HTTP Basic Auth and this was really broken back in 2001. I didn't use templates for these two reasons then and I don't see an easy way to use them now.

I got tired of restarting the server after each change to my application procs so I changed proc DirectDomain to look like this. The change is a little heavy handed (I rename proc to track the source files) but it works great.

 rename proc _proc

 _proc proc { name args body } {
    set ::Source($name)  [info script]
    set ::Source(.$name) [file mtime [info script]]
    _proc $name $args $body

 proc DirectDomain {prefix sock suffix} {
    global Direct
    global env
    upvar #0 Httpd$sock data

    # Set up the environment a-la CGI.

    Cgi_SetEnv $sock $prefix$suffix

    # Source the command script?
    if { [catch {
        puts "Check $::Source($prefix$suffix)"
        if { [file mtime $::Source($prefix$suffix)] != $::Source(.$prefix$suffix) } {
            puts "Sourcing $::Source($prefix$suffix)"
            source $::Source($prefix$suffix)
    } reply] } {
        puts $reply

    # Prepare an argument data from the query data.
    Url_QuerySetup $sock
    set cmd [Direct_MarshallArguments $prefix $suffix]

    if {$cmd == ""} {
        Doc_NotFound $sock

    # Eval the command.  Errors can be used to trigger redirects.

    set code [catch $cmd result]

    set type text/html
    upvar #0 $prefix$suffix aType
    if {[info exist aType]} {
        set type $aType

    DirectRespond $sock $code $result $type