Forum Discussion

Josh_B_152229's avatar
Josh_B_152229
Icon for Nimbostratus rankNimbostratus
May 20, 2015

Calling procs dynamically

I have successfully tested calling procs like this:

eval call [string tolower {HTTP::host}]::procName

However, I'm trying to stop using HTTP::host directly because the TCL checker freaks completely out thinking things are out of context when this type of call is defined outside of an event. I understand that and am trying to work around it by using

set host [string tolower [HTTP::host]]
and all kinds of other dumbness. I'm not expanding/unpacking the variable properly. All of the following fail:

call $host::procName $arg1 $arg2

eval call [string tolower {$host}]::procName $arg1 $arg2

eval [call {$host}]::procName $arg1 $arg2

However, as expected, using

actualValueInHostVar::procname $arg1 $arg2
works perfectly. I know that someone out there can set me straight on this.

Thanks.

  • Much progress has been made. What I found is incredibly frustrating, but I assume it's because I was (somehow) "doing it wrong."

    The goal was to dynamically call a proc named

    http_request
    inside a rule that was named the same as an expected
    [HTTP::host]
    (something that would resolve to the virtual server and be handled by the rule). I have had much success with something very similar before where I set a variable based on a datagroup lookup and performed something simlar to
    eval call [$variable]::procName
    .

    As indicated above, the variable substitution must not act how I think it should and the following not only does not work, but also crashes TMM on 11.6.0 HF3:

    set host [string tolower [HTTP::host]]
    set uri [string tolower [HTTP::uri]]
    eval call [string tolower {HTTP::host}]::http_request $host $uri
    

    My initial testing shows that defining the entire proc to call as a

    string
    works, but using variable substitution (
    $host
    instead of
    [string tolower [HTTP::host]]
    ) when setting
    http_request
    below doesn't work. Not much testing has been done, yet, but the following appears to behave as I expect it:

    set host [string tolower [HTTP::host]]
    set uri [string tolower [HTTP::uri]]
    set http_request  "[string tolower [HTTP::host]]::http_request"
    eval call $http_request $host $uri
    
    • Josh_B_152229's avatar
      Josh_B_152229
      Icon for Nimbostratus rankNimbostratus
      Update: The last line also works when passing TCL words instead of the variables like so: `eval call $http_request [HTTP::host] [HTTP::uri]` As "expected" as that is, it's exciting to me because I have seen so much unexpected behavior with variable substitution lately.