TIP 140: Tracing Namespace Modifications

Login
State:		Deferred
Type:		Project
Tcl-Version:	9.1
Vote:		Pending
Post-History:	
Author:		Donal K. Fellows <[email protected]>
Created:	04-Jun-2003

Abstract

This TIP allows scripts to register callbacks to monitor alterations to namespaces, such as their deletion, the creation, renaming and deletion of commands within the namespace and modifications to the exports list of the namespace.

Rationale

As part of my work on an experimental [112] implementation, I have discovered that computing the list of public (i.e. exported) commands from a namespace is a comparatively expensive operation. This means that it is necessary (well, highly desirable) to cache the list of exports from a namespace. But then I thought that it might be nice to expose that interface to use to better enable namespaces to support other interesting uses, and that it should be possible to implement the default behaviour in a Tcl script. It is in support of this that I present this TIP; I also add the ability to trace deletion of the namespace as a fairly obvious extension.

Proposed Change at Tcl Script Level

I propose that the [trace] command be extended with a new type of thing to trace: a namespace. The operations that would trigger a trace are:

In each case, the trace callback script will have the fully qualified name of the namespace and the name of the triggering operation appended to it before execution. In the case of command list modification by the creation of a command (which might also be through import of commands from another namespace, for example) there will be an extra parameter being the local name of the command (without namespace separators.)

These changes will be propagated to each of the [trace add], [trace remove] and [trace info] subcommands, of course.

Proposed Change at C API Level

Yet to be designed, but will be based as closely as possible on the existing Tcl trace APIs.

Copyright

This document has been placed in the public domain.