tool(n)
π tool(n) π
okay bestie, so this is the manual page for tool β the TclOO Library (TOOL) Framework, living in section n of the manual. no cap, it's a whole vibe. let's get into it β¨
π¦ SYNOPSIS π¦
package require Tcl 8.6 9
package require sha1
package require dicttool
package require oo::meta
package require oo::dialect
tool::define class_method arglist body
tool::define array name contents
tool::define array_ensemble methodname varname ?cases?
tool::define dict_ensemble methodname varname ?cases?
tool::define method methodname arglist body
tool::define option name dictopts
tool::define property ?branch? field value
tool::define variable name value
object cget option
object configure ?keyvaluelist?
object configure field value ?field? ?value? ?...?
object configurelist ?keyvaluelist?
object forward stub forward
object graft stub forward
object InitializePublic
object Eval_Script ?script?
object Option_Default field
πΈ DESCRIPTION πΈ
So this module is literally the whole Tcl Object Oriented Library framework, aka TOOL. It's giving general purpose framework energy β you can use it all on its own, and it's super easy to extend. main character behaviour fr fr π
TOOL defines a metaclass that hands a bunch of extra keywords to the TclOO description language, plus default behaviors for the objects that make it up, plus top-down integration with everything the oo::meta package brings to the table.
The TOOL metaclass was built with the oo::dialect package, so bestie, you can use it as the base for even more metaclasses. As a metaclass, TOOL has its own "class" class, "object" class, and define namespace. iconic.
package require tool
# tool::class workds just like oo::class
tool::class create myclass {
}
# tool::define works just like oo::define
tool::define myclass method noop {} {}
# tool::define and tool::class understand additional keywords
tool::define myclass array_ensemble mysettings mysettings {}
# And tool interoperates with oo::define
oo::define myclass method do_something {} { return something }
# TOOL and TclOO objects are interchangeable
oo::class create myooclass {
superclass myclass
}
There are several manual pages that go way deeper on specific keywords and methods, so go read those too π«Ά
tool::array_ensembletool::dict_ensembletool::method_ensembletool::objecttool::option_handling
π KEYWORDS π
TOOL adds new keywords (and also modifies some existing ones) that you use when defining classes. BUT β huge caveat β these new keywords are only available through calls to tool::class create or tool::define. no shortcuts, bestie.
tool::define class_method arglist bodyβ Defines a method for the class object itself. This method gets passed on down to descendents of the class, which is not how self method behaves. different vibe entirely.tool::define array name contentsβ Declares a variablenamethat gets initialized as an array, populated withcontents, for objects of this class and for any objects of classes that descend from this class. the family tree eats πtool::define array_ensemble methodname varname ?cases?β Declares a method ensemblemethodnamethat controls access to variablevarname. Thecasesare a key/value list of method names and bodies that get overlaid on top of the standard template. Peeptool::array_ensemblefor more.
One method name is reserved: initialize. initialize declares the initial values to be populated in the array, as a key/value list, and it will not be expressed as a method for the ensemble.
tool::define dict_ensemble methodname varname ?cases?β Declares a method ensemblemethodnamethat controls access to variablevarname. Thecasesare a key/value list of method names and bodies that get overlaid on top of the standard template. Peeptool::dict_ensemblefor more.
One method name is reserved: initialize. initialize declares the initial values to be populated in the array, as a key/value list, and it will not be expressed as a method for the ensemble.
tool::define method methodname arglist bodyβ Ifmethodnamecontains::, the method is treated as part of a method ensemble. Seetool::method_ensembles. Otherwise this command behaves exactly like the standardoo::define methodcommand. literally identical.tool::define option name dictoptsβ Declares an option.dictoptsis a key/value list defining the parameters for the option. Seetool::option_handling.
tool::class create myclass {
option color {
post-command: {puts [list %self%'s %field% is now %value%]}
default: green
}
}
myclass create foo
foo configure color purple
> foo's color is now purple
tool::define property ?branch? field valueβ Defines a new leaf in the class metadata tree π³. With nobranch, the leaf shows up in theconstsection, reachable either by the object'spropertymethod, or viaoo::meta::info class get const field.tool::define variable name valueβ Declares a variablenamethat gets initialized with the valuevaluefor objects of this class, and for any objects of classes that descend from this class. π«
β¨ PUBLIC OBJECT METHODS β¨
The TOOL object mother of all classes defines several methods to enforce consistent behavior all throughout the framework. she's the blueprint, the moment, the standard π
object cget optionβ Returns the value of this object's optionoption. If the propertyoptions_strictis true for this class, calling an option that was not declared by theoptionkeyword will throw an error π. In all other cases, if the value is present in the object'soptionsarray, that value is returned. If it doesn't exist, the object will try to retrieve a property of the same name.object configure ?keyvaluelist?object configure field value ?field? ?value? ?...?β This command injects new values into the object'soptionsarray, following the rules laid out by the option descriptions. Seetool::option_handlingfor the details.configurewill strip leading-'s off of field names, which lets it act in a quasi-backward compatible way to tk options. retro but make it cute πobject configurelist ?keyvaluelist?β This command injects new values into the object'soptionsarray, following the rules laid out by the option descriptions. This one performs validation and alternate storage rules. It will not invoke trigger rules. Seetool::option_handlingfor the details.object forward stub forwardβ A passthrough tooo:objdefine [self] forward.object graft stub forwardβ Delegates the<stub>method to the object or command designated byforward.
tool::object create A
tool::object create B
A graft buddy B
A configure color red
B configure color blue
A cget color
> red
A <buddy> cget color
> blue
π PRIVATE OBJECT METHODS π
object InitializePublicβ Consults the metadata for the class to make sure every array, option, and variable that's been declared but not initialized gets initialized with the default value. This method is called by the constructor and themorphmethod. It's safe to invoke multiple times. no side effects, we love that π«Άobject Eval_Script ?script?β Executes a block of text inside the namespace of the object. Lines that begin with a#are ignored as comments. Commands that begin with::are interpreted as calling a global command. All other Tcl commands that lack a"my"prefix are given one, so the script can exercise internal methods. This method is meant for configuration scripts, where the object's methods are interpreting a domain specific language.
tool::class myclass {
constructor script {
my Eval_Script $script
}
method node {nodename info} {
my variable node
dict set node $nodename $info
}
method get {args} {
my variable node
return [dict get $node $args]
}
}
myclass create movies {
# This block of code is executed by the object
node {The Day the Earth Stood Still} {
date: 1952
characters: {GORT Klatoo}
}
}
movies get {The Day the Earth Stood Still} date:
> 1952
object Option_Default fieldβ Computes the default value for an option. Seetool::option_handling.
π AUTHORS π
Sean Woods
π BUGS, IDEAS, FEEDBACK π
ngl, this document and the package it describes will undoubtedly contain bugs and other problems. Please report them in the category tcloo of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. Also please report any ideas for enhancements you might have for either the package and/or the documentation. we listen, bestie π«Ά
When proposing code changes, please provide unified diffs, i.e. the output of diff -u.
Also note: attachments are strongly preferred over inlined patches. You can make attachments by going to the Edit form of the ticket immediately after creating it, and then using the left-most button in the secondary navigation bar. iykyk.
β KEYWORDS β
TOOL, TclOO, framework
π CATEGORY π
TclOO
π COPYRIGHT π
Copyright (c) 2015 Sean Woods <yoda@etoyoc.com>
okay and that's the whole thing, periodt π
this was tcllib version 0.8, the tool(n) page β thanks for reading the whole thing bestie, you ate that πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2015 Sean Woods <yoda@etoyoc\&.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms