Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/tm.n @ 42

Last change on this file since 42 was 25, checked in by landauf, 17 years ago

added tcl to libs

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