logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

tool - TclOO Library (TOOL) Framework

Authors

       Sean Woods

Bugs, Ideas, Feedback

       This document, and the package it describes, will undoubtedly contain bugs and  other  problems.   Please
       report  such in the category tcloo of the TcllibTrackers [http://core.tcl.tk/tcllib/reportlist].  Please
       also report any ideas for enhancements you may have for either package and/or documentation.

       When proposing code changes, please provide unifieddiffs, i.e the output of diff-u.

       Note further that attachments are strongly preferred over inlined patches. Attachments  can  be  made  by
       going  to the Edit form of the ticket immediately after its creation, and then using the left-most button
       in the secondary navigation bar.

Category

       TclOO

Description

       This module implements the Tcl Object Oriented Library framework, or TOOL. It is intended to be a general
       purpose framework that is useable in its own right, and easily extensible.

       TOOL  defines  a  metaclass  with provides several additional keywords to the TclOO description langauge,
       default behaviors for its consituent objects, and top-down integration with the capabilities provided  by
       the oo::meta package.

       The  TOOL  metaclass  was  build  with  the  oo::dialect  package,  and thus can be used as the basis for
       additional metaclasses. As a metaclass, TOOL has it's own  "class"  class,  "object"  class,  and  define
       namespace.

              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
              }

       Several manual pages go into more detail about specific keywords and methods.

       tool::array_ensembletool::dict_ensembletool::method_ensembletool::objecttool::option_handling

Keywords

       TOOL, TclOO, framework

Name

       tool - TclOO Library (TOOL) Framework

Private Object Methods

objectInitializePublic
              Consults  the  metadata  for  the class to ensure every array, option, and variable which has been
              declared but not initialized is initialized with the default value.  This method is called by  the
              constructor and the morph method. It is safe to invoke multiple times.

       objectEval_Script ?script?
              Executes a block of text within 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, to  allow  the  script  to  exercise  internal
              methods.  This  method  is  intended  for  configuration  scripts,  where the object's methods are
              intepreting 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

       objectOption_Defaultfield
              Computes the default value for an option. See tool::option_handling.

Public Object Methods

       The TOOL object mother of all classes defines several methods to enforces consistent behavior  throughout
       the framework.

       objectcgetoption
              Return  the  value of this object's option option. If the propertyoptions_strict is true for this
              class, calling an option which was not declared by the option keyword will throw an error. In  all
              other  cases  if  the value is present in the object's options array that value is returned. If it
              does not exist, the object will attempt to retrieve a property of the same name.

       objectconfigure ?keyvaluelist?

       objectconfigurefieldvalue ?field? ?value? ?...?
              This command will inject new values into the objects options array, according to the rules as  set
              forth  by  the  option  descriptions. See tool::option_handling for details.  configure will strip
              leading -'s off of field names, allowing it to behave in a quasi-backward compatible manner to  tk
              options.

       objectconfigurelist ?keyvaluelist?
              This  command will inject new values into the objects options array, according to the rules as set
              forth by the option descriptions. This command  will  perform  validation  and  alternate  storage
              rules. It will not invoke trigger rules. See tool::option_handling for details.

       objectforwardstubforward
              A passthrough to oo:objdefine[self]forwardobjectgraftstubforward
              Delegates the <stub> method to the object or command designated by forward

              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

Synopsis

       package require Tcl8.69

       package require sha1

       package require dicttool

       package require oo::meta

       package require oo::dialect

       tool::define class_methodarglistbody

       tool::define arraynamecontents

       tool::define array_ensemblemethodnamevarname ?cases?

       tool::define dict_ensemblemethodnamevarname ?cases?

       tool::define methodmethodnamearglistbody

       tool::define optionnamedictopts

       tool::define property ?branch? fieldvalue

       tool::define variablenamevalueobjectcgetoptionobjectconfigure ?keyvaluelist?

       objectconfigurefieldvalue ?field? ?value? ?...?

       objectconfigurelist ?keyvaluelist?

       objectforwardstubforwardobjectgraftstubforwardobjectInitializePublicobjectEval_Script ?script?

       objectOption_Defaultfield

________________________________________________________________________________________________________________

See Also