1oo::util(n)               Utility commands for TclOO               oo::util(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       oo::util - Utility commands for TclOO
9

SYNOPSIS

11       package require Tcl  8.5
12
13       package require TclOO
14
15       package require oo::util  ?1.2.2?
16
17       mymethod method ?arg...?
18
19       classmethod name arguments body
20
21       classvariable ?arg...?
22
23       link method...
24
25       link {alias method}...
26
27       ooutil::singleton ?arg...?
28
29______________________________________________________________________________
30

DESCRIPTION

32       This  package provides a convenience command for the easy specification
33       of instance methods as callback commands, like timers, file events,  Tk
34       bindings, etc.
35

COMMANDS

37       mymethod method ?arg...?
38              This  command  is  available within instance methods. It takes a
39              method name and, possibly, arguments for the method and  returns
40              a  command  prefix  which,  when executed, will invoke the named
41              method of the object we are in, with the provided arguments, and
42              any others supplied at the time of actual invokation.
43
44              Note:  The  command is equivalent to and named after the command
45              provided by the OO package snit for the same purpose.
46
47       classmethod name arguments body
48              This command is available within class definitions. It  takes  a
49              method  name and, possibly, arguments for the method and creates
50              a method on the class, available to a user of the class  and  of
51              derived classes.
52
53              Note:  The  command is equivalent to the command typemethod pro‐
54              vided by the OO package snit for the same purpose.
55
56              Example
57
58
59              oo::class create ActiveRecord {
60                  classmethod find args { puts "[self] called with arguments: $args" }
61              }
62              oo::class create Table {
63                  superclass ActiveRecord
64              }
65              puts [Table find foo bar]
66              # ======
67              # which will write
68              # ======
69              # ::Table called with arguments: foo bar
70
71
72       classvariable ?arg...?
73              This command is available within instance methods.  It  takes  a
74              series  of  variable  names  and  makes  them  available  in the
75              method's scope. The originating scope for the variables  is  the
76              class (instance) the object instance belongs to. In other words,
77              the referenced variables are shared  between  all  instances  of
78              their class.
79
80              Note: The command is roughly equivalent to the command typevari‐
81              able provided by the OO package snit for the same  purpose.  The
82              difference  is  that  it  cannot be used in the class definition
83              itself.
84
85              Example:
86
87
88              % oo::class create Foo {
89                  method bar {z} {
90                      classvariable x y
91                      return [incr x $z],[incr y]
92                  }
93              }
94              ::Foo
95              % Foo create a
96              ::a
97              % Foo create b
98              ::b
99              % a bar 2
100              2,1
101              % a bar 3
102              5,2
103              % b bar 7
104              12,3
105              % b bar -1
106              11,4
107              % a bar 0
108              11,5
109
110
111       link method...
112
113       link {alias method}...
114              This command is available within instance methods.  It  takes  a
115              list  of method names and/or pairs of alias- and method-name and
116              makes the named methods available to all instance methods  with‐
117              out requiring the my command.
118
119              The alias name under which the method becomes available defaults
120              to the method name, except where explicitly specified through an
121              alias/method pair.
122
123              Examples:
124
125
126                  link foo
127                  # The method foo is now directly accessible as foo instead of my foo.
128
129                  link {bar foo}
130                  # The method foo is now directly accessible as bar.
131
132                  link a b c
133                  # The methods a, b, and c all become directly acessible under their
134                  # own names.
135
136
137              The  main use of this command is expected to be in instance con‐
138              structors, for convenience, or to set up some methods for use in
139              a mini DSL.
140
141       ooutil::singleton ?arg...?
142              This  command  is  a  meta-class,  i.e. a variant of the builtin
143              oo::class which ensures that it creates only a  single  instance
144              of the classes defined with it.
145
146              Syntax and results are like for oo::class.
147
148              Example:
149
150
151              % oo::class create example {
152                 self mixin singleton
153                 method foo {} {self}
154              }
155              ::example
156              % [example new] foo
157              ::oo::Obj22
158              % [example new] foo
159              ::oo::Obj22
160
161

AUTHORS

163       Donal Fellows, Andreas Kupries
164

BUGS, IDEAS, FEEDBACK

166       This  document,  and the package it describes, will undoubtedly contain
167       bugs and other problems.  Please report such in the  category  oo::util
168       of  the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].  Please
169       also report any ideas for enhancements you may have for either  package
170       and/or documentation.
171
172       When proposing code changes, please provide unified diffs, i.e the out‐
173       put of diff -u.
174
175       Note further that  attachments  are  strongly  preferred  over  inlined
176       patches.  Attachments  can  be  made  by  going to the Edit form of the
177       ticket immediately after its creation, and  then  using  the  left-most
178       button in the secondary navigation bar.
179

SEE ALSO

181       snit(n)
182

KEYWORDS

184       TclOO, callback, class methods, class variables, command prefix, curry‐
185       ing, method reference, my method, singleton
186

CATEGORY

188       Utility
189
191       Copyright (c) 2011-2015 Andreas Kupries, BSD licensed
192
193
194
195
196tcllib                               1.2.2                         oo::util(n)
Impressum