Seth Woolley's Man Viewer

package(n) - package, package - Facilities for package loading and version control - man n package

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

package(n)                   Tcl Built-In Commands                  package(n)



NAME
       package - Facilities for package loading and version(1,3,5) control

SYNOPSIS
       package forget ?package package ...?
       package ifneeded package version(1,3,5) ?script?
       package names
       package present ?-exact? package ?version(1,3,5)?
       package provide package ?version(1,3,5)?
       package require ?-exact? package ?version(1,3,5)?
       package unknown ?command?
       package vcompare version1 version2
       package versions package
       package vsatisfies version1 version2


DESCRIPTION
       This  command keeps a simple database of the packages available for use
       by the current interpreter and how to load(7,n) them into  the  interpreter.
       It supports multiple versions of each package and arranges for the cor-
       rect version(1,3,5) of a package to be loaded based on what is needed  by  the
       application.   This  command  also detects and reports version(1,3,5) clashes.
       Typically, only the package require and package  provide  commands  are
       invoked  in(1,8)  normal Tcl scripts;  the other commands are used primarily
       by system scripts that maintain the package database.

       The behavior of the package command is determined by  its  first  argu-
       ment.  The following forms are permitted:

       package forget ?package package ...?
              Removes  all  information about each specified package from this
              interpreter, including  information  provided  by  both  package
              ifneeded and package provide.

       package ifneeded package version(1,3,5) ?script?
              This  command  typically  appears  only  in(1,8) system configuration
              scripts to set(7,n,1 builtins) up the package database.   It  indicates  that  a
              particular  version(1,3,5)  of  a  particular  package  is available if(3,n)
              needed, and that the package can be added to the interpreter  by
              executing  script.  The script is saved in(1,8) a database for use by
              subsequent package require commands;  typically, script sets  up
              auto-loading  for  the  commands  in(1,8)  the package (or calls load(7,n)
              and/or source directly), then invokes package provide  to  indi-
              cate  that  the package is present.  There may be information in(1,8)
              the database for several different versions of a single package.
              If  the  database  already  contains information for package and
              version(1,3,5), the new script  replaces  the  existing  one.   If  the
              script  argument is omitted, the current script for version(1,3,5) ver-
              sion of package package is returned, or an empty  string(3,n)  if(3,n)  no
              package  ifneeded  command has been invoked for this package and
              version(1,3,5).

       package names
              Returns a list of the names of all packages in(1,8)  the  interpreter
              for  which  a version(1,3,5) has been provided (via package provide) or
              for which a package ifneeded script is available.  The order  of
              elements in(1,8) the list is arbitrary.

       package present ?-exact? package ?version(1,3,5)?
              This  command  is  equivalent  to package require except that it
              does not try and load(7,n) the package if(3,n) it is not already loaded.

       package provide package ?version(1,3,5)?
              This command is invoked to  indicate  that  version(1,3,5)  version(1,3,5)  of
              package  package is now present in(1,8) the interpreter.  It is typi-
              cally invoked once as part of an ifneeded script, and  again  by
              the  package  itself when it is finally loaded.  An error(8,n) occurs
              if(3,n) a different version(1,3,5) of package has been provided by a  previ-
              ous  package  provide command.  If the version(1,3,5) argument is omit-
              ted, then the command returns the version(1,3,5) number  that  is  cur-
              rently  provided,  or an empty string(3,n) if(3,n) no package provide com-
              mand has been invoked for package in(1,8) this interpreter.

       package require ?-exact? package ?version(1,3,5)?
              This command is typically invoked by Tcl code that wishes to use
              a  particular  version(1,3,5)  of  a particular package.  The arguments
              indicate which package is wanted, and the command ensures that a
              suitable  version(1,3,5) of the package is loaded into the interpreter.
              If the command succeeds, it returns the version(1,3,5) number  that  is
              loaded;   otherwise  it  generates an error.  If both the -exact
              switch(1,n) and the version(1,3,5) argument  are  specified  then  only  the
              given  version(1,3,5)  is acceptable.  If -exact is omitted but version(1,3,5)
              is specified, then versions later than version(1,3,5) are also  accept-
              able  as long as they have the same major version(1,3,5) number as ver-
              sion.  If both -exact and version(1,3,5) are omitted then  any  version(1,3,5)
              whatsoever  is  acceptable.  If a version(1,3,5) of package has already
              been provided (by invoking the package  provide  command),  then
              its version(1,3,5) number must satisfy the criteria given by -exact and
              version(1,3,5) and the command  returns  immediately.   Otherwise,  the
              command  searches the database of information provided by previ-
              ous package ifneeded commands to see if(3,n) an acceptable version(1,3,5) of
              the  package  is  available.   If so, the script for the highest
              acceptable version(1,3,5) number is evaluated in(1,8) the global  namespace;
              it  must do whatever is necessary to load(7,n) the package, including
              calling  package  provide  for  the  package.   If  the  package
              ifneeded  database does not contain an acceptable version(1,3,5) of the
              package and a package unknown command has been specified for the
              interpreter  then that command is evaluated in(1,8) the global names-
              pace;  when it completes, Tcl checks again to see if(3,n) the package
              is now provided or if(3,n) there is a package ifneeded script for it.
              If all of these steps fail to provide an acceptable  version(1,3,5)  of
              the package, then the command returns an error.

       package unknown ?command?
              This command supplies a ``last resort'' command to invoke during
              package require if(3,n) no suitable version(1,3,5) of a package can be found
              in(1,8)  the  package  ifneeded database.  If the command argument is
              supplied, it contains the first part of  a  command;   when  the
              command is invoked during a package require command, Tcl appends
              two additional arguments giving the  desired  package  name  and
              version.   For example, if(3,n) command is foo bar and later the com-
              mand package require test 2.4 is invoked, then Tcl will  execute
              the command foo bar test 2.4 to load(7,n) the package.  If no version(1,3,5)
              number is supplied to the package require command, then the ver-
              sion(1,3,5)  argument  for the invoked command will be an empty string.
              If the package unknown command  is  invoked  without  a  command
              argument,  then  the current package unknown script is returned,
              or an empty string(3,n) if(3,n) there is none.  If command is specified as
              an  empty  string(3,n),  then  the  current package unknown script is
              removed, if(3,n) there is one.

       package vcompare version1 version2
              Compares the two version(1,3,5) numbers given by version1 and version2.
              Returns -1 if(3,n) version1 is an earlier version(1,3,5) than version2, 0 if(3,n)
              they are equal, and 1 if(3,n) version1 is later than version2.

       package versions package
              Returns a list of all the version(1,3,5) numbers of package  for  which
              information has been provided by package ifneeded commands.

       package vsatisfies version1 version2
              Returns  1  if(3,n)  scripts written for version2 will work unchanged
              with version1 (i.e. version1 is equal to or  greater  than  ver-
              sion2  and they both have the same major version(1,3,5) number), 0 oth-
              erwise.


VERSION NUMBERS
       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(1,3,5) number.  Larger numbers correspond to later versions of a
       package,  with leftmost numbers having greater significance.  For exam-
       ple, version(1,3,5) 2.1 is later than 1.3 and  version(1,3,5)  3.4.6  is  later  than
       3.3.5.   Missing  fields  are equivalent to zeroes:  version(1,3,5) 1.3 is the
       same as version(1,3,5) 1.3.0 and 1.3.0.0, so  it  is  earlier  than  1.3.1  or
       1.3.0.2.   A  later  version(1,3,5) number is assumed to be upwards compatible
       with an earlier version(1,3,5) number as long as both versions have  the  same
       major version(1,3,5) number.  For example, Tcl scripts written for version(1,3,5) 2.3
       of a package should work  unchanged  under  versions  2.3.2,  2.4,  and
       2.5.1.   Changes  in(1,8)  the  major  version(1,3,5)  number  signify incompatible
       changes: if(3,n) code is written to use version(1,3,5) 2.1 of a package, it is  not
       guaranteed to work unmodified with either version(1,3,5) 1.7.3 or version(1,3,5) 3.1.


PACKAGE INDICES
       The recommended way to use packages in(1,8) Tcl is to invoke package require
       and  package  provide  commands  in(1,8)  scripts,  and  use  the  procedure
       pkg_mkIndex to create package index  files.   Once  you've  done  this,
       packages  will  be  loaded automatically in(1,8) response to package require
       commands.  See the documentation for pkg_mkIndex for details.


SEE ALSO
       msgcat(1,n)(n), packagens(n), pkgMkIndex(n)


KEYWORDS
       package, version(1,3,5)



Tcl                                   7.5                           package(n)

References for this manual (incoming links)