Feather::Override (Under development)

Last updated: 8th July 1999 at 10:50 BST

Commands

feather::override

Description

This command allows a Tcl script to change the behaviour of an existing command without polluting the namespace with renamed commands. It works by intercepting calls through the Command structure associated with each command. Commands can be overridden multiple times and can be restored in any order.

Arguments

command
The name of a command which is to be, or already has been overridden.

original-command
This is a handle which can be used to manage an override without worrying about whether or not the command has been overridden again.

It can also be used as a command in which case it has the same behaviour as the overridden command had before it was overridden.

overriding-command
This is either the name of a command, or a command object. It is invoked instead of the overridden command.

Syntax

feather::override command command ?overriding-command?
Modifies the behaviour of command to call the optional overriding-command. If it is not specified then [command] will return an error until an overriding-command is set using feather::override set.

Returns an original-command.

feather::override get original-command
Returns the overriding-command associated with original-command.

feather::override original command
Returns the original-command which is currently associated with command.

feather::override restore original-command
Removes the effect of the overriding associated with original-command. This does not need to be the last overriding that was done.

feather::override set original-command overriding-command
Sets the overriding-command of the original-command.

Examples

% proc widget-proc {original method args} {
    switch -- $method {
        "configure" {
	    return [feather::invoke $original configure $args]
	}
    }
}
% proc widget {name args} {

    # Create a frame.
    feather::invoke frame [list $name] $args

    # Override the widget command.
    set original [feather::override command $name]

    # Set the overriding command.
    feather::override set $name [feather::curry ::widget-proc $original]

    return $name
}

[email protected]