package.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:10k
- '"
- '" Copyright (c) 1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: package.n,v 1.6.2.3 2006/09/04 19:35:49 hobbs Exp $
- '"
- .so man.macros
- .TH package n 7.5 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- package - Facilities for package loading and version control
- .SH SYNOPSIS
- .nf
- fBpackage forget ?fIpackage package ...fR?
- fBpackage ifneeded fIpackage versionfR ?fIscriptfR?
- fBpackage namesfR
- fBpackage present fR?fB-exactfR? fIpackage fR?fIversionfR?
- fBpackage provide fIpackage fR?fIversionfR?
- fBpackage require fR?fB-exactfR? fIpackage fR?fIversionfR?
- fBpackage unknown fR?fIcommandfR?
- fBpackage vcompare fIversion1 version2fR
- fBpackage versions fIpackagefR
- fBpackage vsatisfies fIversion1 version2fR
- .fi
- .BE
- .SH DESCRIPTION
- .PP
- This command keeps a simple database of the packages available for
- use by the current interpreter and how to load them into the
- interpreter.
- It supports multiple versions of each package and arranges
- for the correct version of a package to be loaded based on what
- is needed by the application.
- This command also detects and reports version clashes.
- Typically, only the fBpackage requirefR and fBpackage providefR
- commands are invoked in normal Tcl scripts; the other commands are used
- primarily by system scripts that maintain the package database.
- .PP
- The behavior of the fBpackagefR command is determined by its first argument.
- The following forms are permitted:
- .TP
- fBpackage forget ?fIpackage package ...fR?
- Removes all information about each specified package from this interpreter,
- including information provided by both fBpackage ifneededfR and
- fBpackage providefR.
- .TP
- fBpackage ifneeded fIpackage versionfR ?fIscriptfR?
- This command typically appears only in system configuration
- scripts to set up the package database.
- It indicates that a particular version of
- a particular package is available if needed, and that the package
- can be added to the interpreter by executing fIscriptfR.
- The script is saved in a database for use by subsequent
- fBpackage requirefR commands; typically, fIscriptfR
- sets up auto-loading for the commands in the package (or calls
- fBloadfR and/or fBsourcefR directly), then invokes
- fBpackage providefR to indicate that the package is present.
- There may be information in the database for several different
- versions of a single package.
- If the database already contains information for fIpackagefR
- and fIversionfR, the new fIscriptfR replaces the existing
- one.
- If the fIscriptfR argument is omitted, the current script for
- version fIversionfR of package fIpackagefR is returned,
- or an empty string if no fBpackage ifneededfR command has
- been invoked for this fIpackagefR and fIversionfR.
- .TP
- fBpackage namesfR
- Returns a list of the names of all packages in the
- interpreter for which a version has been provided (via
- fBpackage providefR) or for which a fBpackage ifneededfR
- script is available.
- The order of elements in the list is arbitrary.
- .TP
- fBpackage present fR?fB-exactfR? fIpackage fR?fIversionfR?
- This command is equivalent to fBpackage requirefR except that it
- does not try and load the package if it is not already loaded.
- .TP
- fBpackage provide fIpackage fR?fIversionfR?
- This command is invoked to indicate that version fIversionfR
- of package fIpackagefR is now present in the interpreter.
- It is typically invoked once as part of an fBifneededfR script,
- and again by the package itself when it is finally loaded.
- An error occurs if a different version of fIpackagefR has been
- provided by a previous fBpackage providefR command.
- If the fIversionfR argument is omitted, then the command
- returns the version number that is currently provided, or an
- empty string if no fBpackage providefR command has been
- invoked for fIpackagefR in this interpreter.
- .TP
- fBpackage require fR?fB-exactfR? fIpackage fR?fIversionfR?
- This command is typically invoked by Tcl code that wishes to use
- a particular version of a particular package. The arguments
- indicate which package is wanted, and the command ensures that
- a suitable version of the package is loaded into the interpreter.
- If the command succeeds, it returns the version number that is
- loaded; otherwise it generates an error.
- If both the fB-exactfR
- switch and the fIversionfR argument are specified then only the
- given version is acceptable. If fB-exactfR is omitted but
- fIversionfR is specified, then versions later than fIversionfR
- are also acceptable as long as they have the same major version
- number as fIversionfR.
- If both fB-exactfR and fIversionfR are omitted then any
- version whatsoever is acceptable.
- If a version of fIpackagefR has already been provided (by invoking
- the fBpackage providefR command), then its version number must
- satisfy the criteria given by fB-exactfR and fIversionfR and
- the command returns immediately.
- Otherwise, the command searches the database of information provided by
- previous fBpackage ifneededfR commands to see if an acceptable
- version of the package is available.
- If so, the script for the highest acceptable version number is evaluated
- in the global namespace;
- it must do whatever is necessary to load the package,
- including calling fBpackage providefR for the package.
- If the fBpackage ifneededfR database does not contain an acceptable
- version of the package and a fBpackage unknownfR command has been
- specified for the interpreter then that command is evaluated in the
- global namespace; when
- it completes, Tcl checks again to see if the package is now provided
- or if there is a fBpackage ifneededfR script for it.
- If all of these steps fail to provide an acceptable version of the
- package, then the command returns an error.
- .TP
- fBpackage unknown fR?fIcommandfR?
- This command supplies a ``last resort'' command to invoke during
- fBpackage requirefR if no suitable version of a package can be found
- in the fBpackage ifneededfR database.
- If the fIcommandfR argument is supplied, it contains the first part
- of a command; when the command is invoked during a fBpackage requirefR
- command, Tcl appends two additional arguments giving the desired package
- name and version.
- For example, if fIcommandfR is fBfoo barfR and later the command
- fBpackage require test 2.4fR is invoked, then Tcl will execute
- the command fBfoo bar test 2.4fR to load the package.
- If no version number is supplied to the fBpackage requirefR command,
- then the version argument for the invoked command will be an empty string.
- If the fBpackage unknownfR command is invoked without a fIcommandfR
- argument, then the current fBpackage unknownfR script is returned,
- or an empty string if there is none.
- If fIcommandfR is specified as an empty string, then the current
- fBpackage unknownfR script is removed, if there is one.
- .TP
- fBpackage vcompare fIversion1 version2fR
- Compares the two version numbers given by fIversion1fR and fIversion2fR.
- Returns -1 if fIversion1fR is an earlier version than fIversion2fR,
- 0 if they are equal, and 1 if fIversion1fR is later than fBversion2fR.
- .TP
- fBpackage versions fIpackagefR
- Returns a list of all the version numbers of fIpackagefR
- for which information has been provided by fBpackage ifneededfR
- commands.
- .TP
- fBpackage vsatisfies fIversion1 version2fR
- Returns 1 if scripts written for fIversion2fR will work unchanged
- with fIversion1fR (i.e. fIversion1fR is equal to or greater
- than fIversion2fR and they both have the same major version
- number), 0 otherwise.
- .SH "VERSION NUMBERS"
- .PP
- Version numbers consist of one or more decimal numbers separated
- by dots, such as 2 or 1.162 or 3.1.13.1.
- The first number is called the major version number.
- Larger numbers correspond to later versions of a package, with
- leftmost numbers having greater significance.
- For example, version 2.1 is later than 1.3 and version
- 3.4.6 is later than 3.3.5.
- Missing fields are equivalent to zeroes: version 1.3 is the
- same as version 1.3.0 and 1.3.0.0, so it is earlier than 1.3.1 or 1.3.0.2.
- A later version number is assumed to be upwards compatible with
- an earlier version number as long as both versions have the same
- major version number.
- For example, Tcl scripts written for version 2.3 of a package should
- work unchanged under versions 2.3.2, 2.4, and 2.5.1.
- Changes in the major version number signify incompatible changes:
- if code is written to use version 2.1 of a package, it is not guaranteed
- to work unmodified with either version 1.7.3 or version 3.1.
- .SH "PACKAGE INDICES"
- .PP
- The recommended way to use packages in Tcl is to invoke fBpackage requirefR
- and fBpackage providefR commands in scripts, and use the procedure
- fBpkg_mkIndexfR to create package index files.
- Once you've done this, packages will be loaded automatically
- in response to fBpackage requirefR commands.
- See the documentation for fBpkg_mkIndexfR for details.
- .SH EXAMPLES
- To state that a Tcl script requires the Tk and http packages, put this
- at the top of the script:
- .CS
- fBpackage requirefR Tk
- fBpackage requirefR http
- .CE
- .PP
- To test to see if the Snack package is available and load if it is
- (often useful for optional enhancements to programs where the loss of
- the functionality is not critical) do this:
- .CS
- if {[catch {fBpackage requirefR Snack}]} {
- # Error thrown - package not found.
- # Set up a dummy interface to work around the absence
- } else {
- # We have the package, configure the app to use it
- }
- .CE
- .SH "SEE ALSO"
- msgcat(n), packagens(n), pkgMkIndex(n)
- .SH KEYWORDS
- package, version