One of the reasons for creating Tarcel was to make it easier to create modules out of multiple files. Modules have definite benefits: they are faster to load and are simpler to deploy.
As an example, if you have the following files that you would like to put together to form a module called translator-0.1.tm:
translator.tcl
lib/deutsch.tcl
lib/english.tcl
lib/italiano.tcl
translator.tcl contains:
namespace eval translator {
variable translations [dict create]
}
proc translator::addTranslations {language _translations} {
variable translations
dict set translations $language $_translations
}
source lib/deutsch.tcl
source lib/english.tcl
source lib/italiano.tcl
proc translator::englishTo {language englishWord} {
variable translations
dict get $translations $language $englishWord
}
lib/deutsch.tcl contains:
translator::addTranslations deutsch {
welcome willkommen
}
lib/english.tcl contains:
translator::addTranslations english {
welcome welcome
}
lib/italiano.tcl contains:
translator::addTranslations italiano {
welcome benvenuti
}
You can create a module, translator-0.1.tm, from these files using the following translator.tarcel file:
set files [list \
translator.tcl \
[file join lib deutsch.tcl] \
[file join lib english.tcl] \
[file join lib italiano.tcl]
]
set version 0.1
set baseDir translator-$version.vfs
set outputFilename translator-$version.tm
import [file join $baseDir app] $files
config set version $version
config set homepage "http://example.com/project/translator"
set initScript {
source [file join @baseDir app translator.tcl]
}
config set init [string map [list @baseDir $baseDir] $initScript]
config set outputFilename $outputFilename
Wrap the files into a module using the following:
$ tclsh tarcel.tcl wrap translator.tarcel
Now create a test file, translator.test.tcl:
package require tcltest
namespace import tcltest::*
::tcl::tm::path add [file normalize .]
package require translator
test englishTo-1 {Ensure translates from English to German} -body {
translator::englishTo deutsch welcome
} -result {willkommen}
test englishTo-2 {Ensure translates from English to Italian} -body {
translator::englishTo italiano welcome
} -result {benvenuti}
cleanupTests
Finally you can now run the test and see that it treats the module just as if it was originally created as a single file:
$ tclsh translator.test.tcl
Find out More
To find out more have a look at the Tarcel Project page and the following articles: