[25] | 1 | '\" |
---|
| 2 | '\" Copyright (c) 2004 Andreas Kupries <andreas_kupries@users.sourceforge.net> |
---|
| 3 | '\" |
---|
| 4 | '\" See the file "license.terms" for information on usage and redistribution |
---|
| 5 | '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 6 | '\" |
---|
| 7 | '\" RCS: @(#) $Id: tm.n,v 1.14 2008/01/18 15:59:22 dkf Exp $ |
---|
| 8 | '\" |
---|
| 9 | .so man.macros |
---|
| 10 | .TH tm n 8.5 Tcl "Tcl Built-In Commands" |
---|
| 11 | .BS |
---|
| 12 | '\" Note: do not modify the .SH NAME line immediately below! |
---|
| 13 | .SH NAME |
---|
| 14 | tm \- Facilities for locating and loading of Tcl Modules |
---|
| 15 | .SH SYNOPSIS |
---|
| 16 | .nf |
---|
| 17 | \fB::tcl::tm::path\fR \fBadd\fR \fIpath\fR... |
---|
| 18 | \fB::tcl::tm::path\fR \fBremove\fR \fIpath\fR... |
---|
| 19 | \fB::tcl::tm::path\fR \fBlist\fR |
---|
| 20 | \fB::tcl::tm::roots\fR \fIpath\fR... |
---|
| 21 | .fi |
---|
| 22 | .BE |
---|
| 23 | .SH DESCRIPTION |
---|
| 24 | This document describes the facilities for locating and loading Tcl |
---|
| 25 | Modules. The following commands are supported: |
---|
| 26 | .TP |
---|
| 27 | \fB::tcl::tm::path\fR \fBadd\fR \fIpath\fR... |
---|
| 28 | . |
---|
| 29 | The paths are added at the head to the list of module paths, in order |
---|
| 30 | of appearance. This means that the last argument ends up as the new |
---|
| 31 | head of the list. |
---|
| 32 | .RS |
---|
| 33 | .PP |
---|
| 34 | The command enforces the restriction that no path may be an ancestor |
---|
| 35 | directory of any other path on the list. If any of the new paths |
---|
| 36 | violates this restriction an error will be raised, before any of the |
---|
| 37 | paths have been added. In other words, if only one path argument |
---|
| 38 | violates the restriction then none will be added. |
---|
| 39 | .PP |
---|
| 40 | If a path is already present as is, no error will be raised and no |
---|
| 41 | action will be taken. |
---|
| 42 | .PP |
---|
| 43 | Paths are searched later in the order of their appearance in the |
---|
| 44 | list. As they are added to the front of the list they are searched in |
---|
| 45 | reverse order of addition. In other words, the paths added last are |
---|
| 46 | looked at first. |
---|
| 47 | .RE |
---|
| 48 | .TP |
---|
| 49 | \fB::tcl::tm::path\fR \fBremove\fR \fIpath\fR... |
---|
| 50 | . |
---|
| 51 | Removes the paths from the list of module paths. The command silently |
---|
| 52 | ignores all paths which are not on the list. |
---|
| 53 | .TP |
---|
| 54 | \fB::tcl::tm::path\fR \fBlist\fR |
---|
| 55 | . |
---|
| 56 | Returns a list containing all registered module paths, in the order |
---|
| 57 | that they are searched for modules. |
---|
| 58 | .TP |
---|
| 59 | \fB::tcl::tm::roots\fR \fIpath\fR... |
---|
| 60 | . |
---|
| 61 | Similar to \fBpath add\fR, and layered on top of it. This command |
---|
| 62 | takes a list of paths, extends each with |
---|
| 63 | .QW "\fBtcl\fIX\fB/site-tcl\fR" , |
---|
| 64 | and |
---|
| 65 | .QW "\fBtcl\fIX\fB/\fIX\fB.\fIy\fR" , |
---|
| 66 | for major version \fIX\fR of the |
---|
| 67 | Tcl interpreter and minor version \fIy\fR less than or equal to the |
---|
| 68 | minor version of the interpreter, and adds the resulting set of paths |
---|
| 69 | to the list of paths to search. |
---|
| 70 | .RS |
---|
| 71 | .PP |
---|
| 72 | This command is used internally by the system to set up the |
---|
| 73 | system-specific default paths. |
---|
| 74 | .PP |
---|
| 75 | The command has been exposed to allow a build system to define |
---|
| 76 | additional root paths beyond those described by this document. |
---|
| 77 | .RE |
---|
| 78 | .SH "MODULE DEFINITION" |
---|
| 79 | A Tcl Module is a Tcl Package contained in a single file, and no other |
---|
| 80 | files required by it. This file has to be \fBsource\fRable. In other |
---|
| 81 | words, a Tcl Module is always imported via: |
---|
| 82 | .CS |
---|
| 83 | source module_file |
---|
| 84 | .CE |
---|
| 85 | .PP |
---|
| 86 | The \fBload\fR command is not directly used. This restriction is not |
---|
| 87 | an actual limitation, as some may believe. |
---|
| 88 | Ever since 8.4 the Tcl \fBsource\fR command reads only until the first |
---|
| 89 | ^Z character. This allows us to combine an arbitrary Tcl script with |
---|
| 90 | arbitrary binary data into one file, where the script processes the |
---|
| 91 | attached data in any it chooses to fully import and activate the |
---|
| 92 | package. |
---|
| 93 | .PP |
---|
| 94 | The name of a module file has to match the regular expression: |
---|
| 95 | .CS |
---|
| 96 | ([[:alpha:]][:[:alnum:]]*)-([[:digit:]].*)\e.tm |
---|
| 97 | .CE |
---|
| 98 | .PP |
---|
| 99 | The first capturing parentheses provides the name of the package, the |
---|
| 100 | second clause its version. In addition to matching the pattern, the |
---|
| 101 | extracted version number must not raise an error when used in the |
---|
| 102 | command: |
---|
| 103 | .CS |
---|
| 104 | package vcompare $version 0 |
---|
| 105 | .CE |
---|
| 106 | .PP |
---|
| 107 | .SH "FINDING MODULES" |
---|
| 108 | The directory tree for storing Tcl modules is separate from other |
---|
| 109 | parts of the filesystem and independent of \fBauto_path\fR. |
---|
| 110 | .PP |
---|
| 111 | Tcl Modules are searched for in all directories listed in the result |
---|
| 112 | of the command \fB::tcl::tm::path list\fR. |
---|
| 113 | This is called the \fIModule path\fR. Neither the \fBauto_path\fR nor |
---|
| 114 | the \fBtcl_pkgPath\fR variables are used. |
---|
| 115 | All directories on the module path have to obey one restriction: |
---|
| 116 | .RS |
---|
| 117 | .PP |
---|
| 118 | For any two directories, neither is an ancestor directory of the |
---|
| 119 | other. |
---|
| 120 | .RE |
---|
| 121 | .PP |
---|
| 122 | This is required to avoid ambiguities in package naming. If for |
---|
| 123 | example the two directories |
---|
| 124 | .QW "\fIfoo/\fR" |
---|
| 125 | and |
---|
| 126 | .QW "\fIfoo/cool\fR" |
---|
| 127 | were on |
---|
| 128 | the path a package named \fBcool::ice\fR could be found via the |
---|
| 129 | names \fBcool::ice\fR or \fBice\fR, the latter potentially |
---|
| 130 | obscuring a package named \fBice\fR, unqualified. |
---|
| 131 | .PP |
---|
| 132 | Before the search is started, the name of the requested package is |
---|
| 133 | translated into a partial path, using the following algorithm: |
---|
| 134 | .RS |
---|
| 135 | .PP |
---|
| 136 | All occurrences of |
---|
| 137 | .QW "\fB::\fR" |
---|
| 138 | in the package name are replaced by |
---|
| 139 | the appropriate directory separator character for the platform we are |
---|
| 140 | on. On Unix, for example, this is |
---|
| 141 | .QW "\fB/\fR" . |
---|
| 142 | .RE |
---|
| 143 | .PP |
---|
| 144 | Example: |
---|
| 145 | .RS |
---|
| 146 | .PP |
---|
| 147 | The requested package is \fBencoding::base64\fR. The generated |
---|
| 148 | partial path is |
---|
| 149 | .QW "\fIencoding/base64\fR" . |
---|
| 150 | .RE |
---|
| 151 | .PP |
---|
| 152 | After this translation the package is looked for in all module paths, |
---|
| 153 | by combining them one-by-one, first to last with the partial path to |
---|
| 154 | form a complete search pattern. Note that the search algorithm rejects |
---|
| 155 | all files where the filename does not match the regular expression |
---|
| 156 | given in the section \fBMODULE DEFINITION\fR. For the remaining |
---|
| 157 | files \fIprovide scripts\fR are generated and added to the package |
---|
| 158 | ifneeded database. |
---|
| 159 | .PP |
---|
| 160 | The algorithm falls back to the previous unknown handler when none of |
---|
| 161 | the found module files satisfy the request. If the request was |
---|
| 162 | satisfied the fall-back is ignored. |
---|
| 163 | .PP |
---|
| 164 | Note that packages in module form have \fIno\fR control over the |
---|
| 165 | \fIindex\fR and \fIprovide script\fRs entered into the package |
---|
| 166 | database for them. |
---|
| 167 | For a module file \fBMF\fR the \fIindex script\fR is always: |
---|
| 168 | .CS |
---|
| 169 | package ifneeded \fBPNAME PVERSION\fR [list source \fBMF\fR] |
---|
| 170 | .CE |
---|
| 171 | and the \fIprovide script\fR embedded in the above is: |
---|
| 172 | .CS |
---|
| 173 | source \fBMF\fR |
---|
| 174 | .CE |
---|
| 175 | .PP |
---|
| 176 | Both package name \fBPNAME\fR and package version \fBPVERSION\fR are |
---|
| 177 | extracted from the filename \fBMF\fR according to the definition |
---|
| 178 | below: |
---|
| 179 | .CS |
---|
| 180 | \fBMF\fR = /module_path/\fBPNAME\(fm\fR-\fBPVERSION\fR.tm |
---|
| 181 | .CE |
---|
| 182 | .PP |
---|
| 183 | Where \fBPNAME\(fm\fR is the partial path of the module as defined in |
---|
| 184 | section \fBFINDING MODULES\fR, and translated into \fBPNAME\fR by |
---|
| 185 | changing all directory separators to |
---|
| 186 | .QW "\fB::\fR" , |
---|
| 187 | and \fBmodule_path\fR is the path (from the list of paths to search) |
---|
| 188 | that we found the module file under. |
---|
| 189 | .PP |
---|
| 190 | Note also that we are here creating a connection between package names |
---|
| 191 | and paths. Tcl is case-sensitive when it comes to comparing package |
---|
| 192 | names, but there are filesystems which are not, like NTFS. Luckily |
---|
| 193 | these filesystems do store the case of the name, despite not using the |
---|
| 194 | information when comparing. |
---|
| 195 | .PP |
---|
| 196 | Given the above we allow the names for packages in Tcl modules to have |
---|
| 197 | mixed-case, but also require that there are no collisions when |
---|
| 198 | comparing names in a case-insensitive manner. In other words, if a |
---|
| 199 | package \fBFoo\fR is deployed in the form of a Tcl Module, |
---|
| 200 | packages like \fBfoo\fR, \fBfOo\fR, etc. are not allowed |
---|
| 201 | anymore. |
---|
| 202 | .SH "DEFAULT PATHS" |
---|
| 203 | The default list of paths on the module path is computed by a |
---|
| 204 | \fBtclsh\fR as follows, where \fIX\fR is the major version of the Tcl |
---|
| 205 | interpreter and \fIy\fR is less than or equal to the minor version of |
---|
| 206 | the Tcl interpreter. |
---|
| 207 | .PP |
---|
| 208 | All the default paths are added to the module path, even those paths |
---|
| 209 | which do not exist. Non-existent paths are filtered out during actual |
---|
| 210 | searches. This enables a user to create one of the paths searched when |
---|
| 211 | needed and all running applications will automatically pick up any |
---|
| 212 | modules placed in them. |
---|
| 213 | .PP |
---|
| 214 | The paths are added in the order as they are listed below, and for |
---|
| 215 | lists of paths defined by an environment variable in the order they |
---|
| 216 | are found in the variable. |
---|
| 217 | .SS "SYSTEM SPECIFIC PATHS" |
---|
| 218 | .TP |
---|
| 219 | \fBfile normalize [info library]/../tcl\fIX\fB/\fIX\fB.\fIy\fR |
---|
| 220 | . |
---|
| 221 | In other words, the interpreter will look into a directory specified |
---|
| 222 | by its major version and whose minor versions are less than or equal |
---|
| 223 | to the minor version of the interpreter. |
---|
| 224 | .RS |
---|
| 225 | .PP |
---|
| 226 | For example for Tcl 8.4 the paths searched are: |
---|
| 227 | .CS |
---|
| 228 | \fB[info library]/../tcl8/8.4\fR |
---|
| 229 | \fB[info library]/../tcl8/8.3\fR |
---|
| 230 | \fB[info library]/../tcl8/8.2\fR |
---|
| 231 | \fB[info library]/../tcl8/8.1\fR |
---|
| 232 | \fB[info library]/../tcl8/8.0\fR |
---|
| 233 | .CE |
---|
| 234 | .PP |
---|
| 235 | This definition assumes that a package defined for Tcl \fIX\fB.\fIy\fR |
---|
| 236 | can also be used by all interpreters which have the same major number |
---|
| 237 | \fIX\fR and a minor number greater than \fIy\fR. |
---|
| 238 | .RE |
---|
| 239 | .TP |
---|
| 240 | \fBfile normalize EXEC/tcl\fIX\fB/\fIX\fB.\fIy\fR |
---|
| 241 | . |
---|
| 242 | Where \fBEXEC\fR is \fBfile normalize [info nameofexecutable]/../lib\fR |
---|
| 243 | or \fBfile normalize [::tcl::pkgconfig get libdir,runtime]\fR |
---|
| 244 | .RS |
---|
| 245 | .PP |
---|
| 246 | This sets of paths is handled equivalently to the set coming before, |
---|
| 247 | except that it is anchored in \fBEXEC_PREFIX\fR. |
---|
| 248 | For a build with \fBPREFIX\fR = \fBEXEC_PREFIX\fR the two sets are |
---|
| 249 | identical. |
---|
| 250 | .RE |
---|
| 251 | .SS "SITE SPECIFIC PATHS" |
---|
| 252 | .TP |
---|
| 253 | \fBfile normalize [info library]/../tcl\fIX\fB/site-tcl\fR |
---|
| 254 | . |
---|
| 255 | Note that this is always a single entry because \fIX\fR is always a |
---|
| 256 | specific value (the current major version of Tcl). |
---|
| 257 | .SS "USER SPECIFIC PATHS" |
---|
| 258 | .TP |
---|
| 259 | \fB$::env(TCL\fIX\fB.\fIy\fB_TM_PATH)\fR |
---|
| 260 | . |
---|
| 261 | A list of paths, separated by either \fB:\fR (Unix) or \fB;\fR |
---|
| 262 | (Windows). This is user and site specific as this environment variable |
---|
| 263 | can be set not only by the user's profile, but by system configuration |
---|
| 264 | scripts as well. |
---|
| 265 | .RS |
---|
| 266 | .PP |
---|
| 267 | These paths are seen and therefore shared by all Tcl shells in the |
---|
| 268 | \fB$::env(PATH)\fR of the user. |
---|
| 269 | .PP |
---|
| 270 | Note that \fIX\fR and \fIy\fR follow the general rules set out |
---|
| 271 | above. In other words, Tcl 8.4, for example, will look at these 5 |
---|
| 272 | environment variables: |
---|
| 273 | .CS |
---|
| 274 | \fB$::env(TCL8.4_TM_PATH)\fR |
---|
| 275 | \fB$::env(TCL8.3_TM_PATH)\fR |
---|
| 276 | \fB$::env(TCL8.2_TM_PATH)\fR |
---|
| 277 | \fB$::env(TCL8.1_TM_PATH)\fR |
---|
| 278 | \fB$::env(TCL8.0_TM_PATH)\fR |
---|
| 279 | .CE |
---|
| 280 | .RE |
---|
| 281 | .SH "SEE ALSO" |
---|
| 282 | package(n), Tcl Improvement Proposal #189 |
---|
| 283 | .QW "\fITcl Modules\fR" |
---|
| 284 | (online at http://tip.tcl.tk/189.html), Tcl Improvement Proposal #190 |
---|
| 285 | .QW "\fIImplementation Choices for Tcl Modules\fR" |
---|
| 286 | (online at http://tip.tcl.tk/190.html) |
---|
| 287 | .SH "KEYWORDS" |
---|
| 288 | modules, package |
---|