Modify Ensemble Command Resolution BehaviourMiguel SoferNeil Madden$Revision: 1.22 $
This TIP proposes that ensembles resolve all commands in their namespace.
Ensembles as proposed in cannot interoperate with the namespace path and namespace unknown functionality: as they resolve all commands in the caller's scope, it is necessary to define them using fully qualified names to insure that they are found in the ensemble's namespace. But fully qualified names bypass the namespace's path and unknown redirectors.
As an example (and risking "uh-oo" reactions in the present context) I would like to remark that this feature enables lightweight OO systems based on ensembles to provide inheritance of methods via namespace path and namespace unknown.
This TIP proposes to fix this by changing the man page description of the ensemble unknown handler from:
It is up to the unknown handler to supply all namespace qualifiers if the implementing subcommand is not in the namespace of the caller of the ensemble command.
to:
The implementing subcommand is looked up in the ensemble's namespace using normal command location rules.
The description of the -map option should change from:
When non-empty, this option supplies a dictionary that provides a mapping from subcommand names to a list of prefix words to substitute in place of the ensemble command and subcommand words (in a manner similar to an alias created with interp alias; the words are not reparsed after substitution).
to:
When non-empty, this option supplies a dictionary that provides a mapping from subcommand names to a list of prefix words to substitute in place of the ensemble command and subcommand words (in a manner similar to an alias created with interp alias; the words are not reparsed after substitution). The resulting command is invoked with the original arguments in the namespace of the ensemble, though no additional stack frames are pushed in the process.
All scripts that followed previous best-practice and placed fully qualified command names in the command map or returned them from the unknown handler will be unaffected by this change. Only ensembles whose behaviour was undefined previously will be influenced, and then strictly in a positive direction.
[RFE 1577282] [] (which depends on committed [Patch 1577278]) provides an implementation, with tests and docs.
Consider the following script (without FQ names) stored in /tmp/test:ICAgbmFtZXNwYWNlIGV2YWwgYSB7ICAgICAgIHByb2MgY2hlY2sgYXJncyB7cmV0dXJuIFlFU30=ICAgfQ==ICAgbmFtZXNwYWNlIGV2YWwgYiB7ICAgICAgIG5hbWVzcGFjZSBwYXRoIDo6YQ==ICAgICAgIG5hbWVzcGFjZSBlbnNlbWJsZSBjcmVhdGUgXA==ICAgICAgICAgICAtY29tbWFuZCA6OmIgXA==ICAgICAgICAgICAtbWFwIHtnbyBjaGVja30=ICAgfQ==ICAgbmFtZXNwY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iaWd1b3VzIHN1YmNvbW1hbmQgImZvbyI6IG11c3QgYmUgZ28=ICAgcmVzKGR8Z28pICA9IGludmFsaWQgY29tbWFuZCBuYW1lICI6OmQ6OmNoZWNrIg==
After this TIP, it should be
ICAgbWlnQGljZTp+JCB0Y2xzaCAvdG1wL3Rlc3Q=ICAgcmVzKGJ8Zm9vKSA9IHVua25vd24gb3IgYW1iaWd1b3VzIHN1YmNvbW1hbmQgImZvbyI6IG11c3QgYmUgZ28=ICAgcmVzKGJ8Z28pICA9IFlFUw==ICAgcmVzKGN8Zm9vKSA9IFlFUw==ICAgcmVzKGN8Z28pICA9IFlFUw==ICAgcmVzKGR8Zm9vKSA9IHVua25vd24gb3IgYW1iaWd1b3VzIHN1YmNvbW1hbmQgImZvbyI6IG11c3QgYmUgZ28=ICAgcmVzKGR8Z28pICA9IFlFUw==
One commenter asked what the difference would be in the following code:ICAgbmFtZXNwYWNlIGV2YWwgZW5zIHs=ICAgICAgIHByb2MgZm9vIHt9IHs=ICAgICAgICAgICBwdXRzICJDYWxsZXIgbmFtZXNwYWNlIGlzOiBbdXBsZXZlbCAxIG5hbWVzcGFjZSBjdXJyZW50XSI=ICAgICAgICAgICBwdXRzICJJIGFtIFtuYW1lc3BhY2Ugb3JpZ2luIGZvb10iICAgICAgICAgICBwdXRzICJJIGFtIGNhbGxlZCBhczogW2xpbmRleCBbaW5mbyBsZXZlbCAwXSAwXSI=ICAgICAgIH0=ICAgICAgIG5hbWVzcGFjZSBleHBvcnQgZW5zICAgICAgIG5hbWVzcGFjZSBlbnNlbWJsZSBjcmVhdGUgLWNvbW1hbmQgZW5zIC1tYXAge3N1YiBmb299ICAgfQ==ICAgbmFtZXNwYWNlIGV2YWwgY2FsbGVyIHs=ICAgICAgIHByb2MgZm9vIHt9IHs=ICAgICAgICAgICBwdXRzICJDYWxsZXIgbmFtZXNwYWNlIGlzOiBbdXBsZXZlbCAxIG5hbWVzcGFjZSBjdXJyZW50XSI=ICAgICAgICAgICBwdXRzICJJIGFtIFtuYW1lc3BhY2Ugb3JpZ2luIGZvb10iICAgICAgICAgICBwdXRzICJJIGFtIGNhbGxlZCBhczogW2xpbmRleCBbaW5mbyBsZXZlbCAwXSAwXSI=ICAgICAgIH0=ICAgICAgIG5hbWVzcGFjZSBpbXBvcnQgOjplbnM6OmVucw==ICAgICAgIGVucyBzdWI=ICAgfQ==
Today (*) and after the patch this returns:
ICAgQ2FsbGVyIG5hbWVzcGFjZSBpczogOjpjYWxsZXI=ICAgSSBhbSA6OmVuczo6Zm9vICAgSSBhbSBjYWxsZWQgYXM6IGVucw==
(*) Today==2006-24-10, after making info level aware of ensemble rewrites; prior to that date, only the last line would have changed from ::ens::foo to foo.
This document has been placed in the public domain.