1self(n)                         TclOO Commands                         self(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       self - method call internal introspection
9

SYNOPSIS

11       package require TclOO
12
13       self ?subcommand?
14______________________________________________________________________________
15

DESCRIPTION

17       The  self command, which should only be used from within the context of
18       a call to a method (i.e. inside a  method,  constructor  or  destructor
19       body)  is used to allow the method to discover information about how it
20       was called. It takes an argument, subcommand, that tells it  what  sort
21       of  information  is actually desired; if omitted the result will be the
22       same as if self object was invoked. The supported subcommands are:
23
24       self call
25              This returns a two-element list describing the method  implemen‐
26              tations used to implement the current call chain. The first ele‐
27              ment is the same as would be reported by info  object  call  for
28              the  current method (except that this also reports useful values
29              from  within  constructors  and  destructors,  whose  names  are
30              reported  as  <constructor>  and <destructor> respectively), and
31              the second element is an index into  the  first  element's  list
32              that  indicates which actual implementation is currently execut‐
33              ing (the first implementation to execute is always at index 0).
34
35       self caller
36              When the method was invoked from inside another  object  method,
37              this subcommand returns a three element list describing the con‐
38              taining object and  method.  The  first  element  describes  the
39              declaring  object  or class of the method, the second element is
40              the name of the  object  on  which  the  containing  method  was
41              invoked,  and  the third element is the name of the method (with
42              the strings <constructor> and <destructor> indicating  construc‐
43              tors and destructors respectively).
44
45       self class
46              This  returns  the name of the class that the current method was
47              defined within.  Note that this will  change  as  the  chain  of
48              method  implementations  is traversed with next, and that if the
49              method was defined on an object then this will fail.
50
51              If you want the class of the current object,  you  need  to  use
52              this other construct:
53
54                     info object class [self object]
55
56       self filter
57              When  invoked  inside  a filter, this subcommand returns a three
58              element list describing the filter. The first element gives  the
59              name  of the object or class that declared the filter (note that
60              this may be different from the object or class that provided the
61              implementation  of  the  filter),  the  second element is either
62              object or class depending on whether the declaring entity was an
63              object  or  class, and the third element is the name of the fil‐
64              ter.
65
66       self method
67              This returns the name of the current method  (with  the  strings
68              <constructor>   and  <destructor>  indicating  constructors  and
69              destructors respectively).
70
71       self namespace
72              This returns the name of the unique namespace of the object that
73              the method was invoked upon.
74
75       self next
76              When  invoked  from  a  method  that is not at the end of a call
77              chain (i.e. where the next command will invoke an actual  method
78              implementation),  this  subcommand  returns  a  two element list
79              describing the next element in the method call chain; the  first
80              element  is  the  name  of the class or object that declares the
81              next part of the call chain, and the second element is the  name
82              of  the  method (with the strings <constructor> and <destructor>
83              indicating  constructors  and  destructors   respectively).   If
84              invoked  from  a method that is at the end of a call chain, this
85              subcommand returns the empty string.
86
87       self object
88              This returns the name of the object that the method was  invoked
89              upon.
90
91       self target
92              When  invoked  inside  a  filter implementation, this subcommand
93              returns a two element list describing the method being filtered.
94              The  first  element  will  be  the  name  of the declarer of the
95              method, and the second element will be the actual  name  of  the
96              method.
97

EXAMPLES

99       This  example  shows basic use of self to provide information about the
100       current object:
101
102              oo::class create c {
103                  method foo {} {
104                      puts "this is the [self] object"
105                  }
106              }
107              c create a
108              c create b
109              a foo                 prints "this is the ::a object"
110              b foo                 prints "this is the ::b object"
111
112       This demonstrates what a method call chain looks like, and how travers‐
113       ing along it changes the index into it:
114
115              oo::class create c {
116                  method x {} {
117                      puts "Cls: [self call]"
118                  }
119              }
120              c create a
121              oo::objdefine a {
122                  method x {} {
123                      puts "Obj: [self call]"
124                      next
125                      puts "Obj: [self call]"
126                  }
127              }
128              a x      Obj: {{method x object method} {method x ::c method}} 0
129                       Cls: {{method x object method} {method x ::c method}} 1
130                       Obj: {{method x object method} {method x ::c method}} 0
131

SEE ALSO

133       info(n), next(n)
134

KEYWORDS

136       call, introspection, object
137
138
139
140TclOO                                 0.1                              self(n)
Impressum