Access external variables from within proc
I am trying to write a general redirect handler but I need access to a variable external to the proc. Tcl allows globals access to external variables (although most likely they mean a true global which I do not want).
My throught was due to the multiple redirect issue, I would write a proc to do the following:
Proc Redirect {theURL} { set gRespondOrRedirect 1 HTTP::redirect $theURL return }
I then use a call of call library::Redirect "http://myhost.com"
Note I want to set the gRespondOrRedirect variable so it is accessible in any other rule that does a redirect. I use that now by checking if {$gRespondOrRedirect} { return }
I tried the global Tcl command. Upvar is not right for what I want. Does anyone know how I can access a variable in the scope of the connection from within a proc? The obvious "pass it as an argument" defeats the purpose some as if my call is call library::Redirect $gRespondOrRedirect "http://myhost.com" it does not save as much. I believe I would have to change my procedure to this for that to work to handle the call-by-reference:
Proc Redirect {flag theURL} { Pointer reference to original variable flag aliases locally as myFlag. upvar $flag myFlag set myFlag 1 HTTP::redirect $theURL return }
I know this is a new feature, but has anyone gone down this road yet?
Thanks.