2017-11-13

TemplaTcl and 8.6.1

TemplaTcl: a Tcl template engine


在 Tcler'wiki 發現的套件,我在測試以後發現可以使用,並且對下面的使用留言感到疑惑,

I'm trying to run this script and keep getting an error for the following line of script:
$obj($self:interp) eval $tclBuf

經過實測,發現 Windows 7 (64bit) 的 8.6.7 和 openSUSE LEAP 42.3 的  8.6.7 可以正常使用,但是 Ubuntu 14.04 的 8.6.1 會發生同樣的錯誤訊息。

但是 Ubuntu 環境,使用 ActiveTcl 8.6.3 也同樣可以執行,所以目前推定是 Tcl 8.6.1 應該有問題,會導致 TemplaTcl 無法執行。


更新:
在更多測試以後,發現一個很有趣的問題。就是執行 render 之後,內容是會累積的。這在 CGI 程式下有可能沒問題(因為 process 都會再重新執行一次),但是如果是要使用一個像 Tanzer 的 http server,就有可能會出現問題。

(* Tanzer 有自己的 template system,但是因為我是要測試 TemplaTcl,所以拿 TemplaTcl 來用)

目前的解法是執行到最後,將目前的資料清除,
        if {$obj($self:options:printCommand) == "_defaultSpool"} {
            set x [$obj($self:interp) eval {_defaultSpool {} get}]
            $obj($self:interp) eval {_defaultSpool {} clear}

            set obj($self:data) {}
            return $x
        }

而這樣才能夠在 Tanzer 每次 request 時正常的顯示,而不會資料重複。

如果還要修改,再來就是針對小型網頁的優化,就是先讀取檔案內容並且儲存到 dict,然後每次我們需要的時候再從 dict 拿取。 PS. 但是這樣不知道多人環境下會不會有問題

這樣就可以由 Tanzer 作 URL routing,並且撰寫需要動作的部份,需要輸出畫面時,就由 TemplaTcl 來輸出畫面。

沒有留言: