Content-type: text/html
Manpage of ooInfo
ooInfo
Section: TclOO Commands (n)
Updated: 0.1
Index
Return to Main Contents
NAME
info class, info object - introspection for classes and objects
SYNOPSIS
package require TclOO
info object subcommand object ?arg ...
info class subcommand class ?arg ...
DESCRIPTION
The commands info object and info class are ensemble
commands that provide introspection capabilities to the object system, with
the subcommand argument designating which aspect is to be inspectected
and the object or class argument naming the object or class to be
inspected.
OBJECT INTROSPECTION
The following subcommand values are supported by info object:
- info object class object ?className?
-
If className is unspecified, this subcommand returns class of the
object object. If className is present, this subcommand returns a
boolean value indicating whether the object is of that class.
- info object definition object method
-
This subcommand returns a description of the definition of the method named
method of object object. The defintion is described as a two
element list; the first element is the list of arguments to the method in a
form suitable for passing to another call to proc or a method defintion,
and the second element is the body of the method.
- info object filters object
-
This subcommand returns the list of filter methods set on the object.
- info object forward object method
-
This subcommand returns the argument list for the method forwarding called
method that is set on the object called object.
- info object isa category object ?arg?
-
This subcommand tests whether an object belongs to a particular category,
returning a boolean value that indicates whether the object argument
meets the criteria for the category. The supported categories are:
-
- info object isa class object
-
This returns whether object is a class (i.e. an instance of
oo::class or one of its subclasses).
- info object isa metaclass object
-
This returns whether object is a class that can manufacture classes
(i.e. is oo::class or a subclass of it).
- info object isa mixin object class
-
This returns whether class is directly mixed into object.
- info object isa object object
-
This returns whether object really is an object.
- info object isa typeof object class
-
This returns whether class is the type of object (i.e. whether
object is an instance of class or one of its subclasses, whether
direct or indirect).
- info object methods object ?option...?
-
This subcommand returns a list of all public (i.e. exported) methods of the
object called object. Any of the following options may be
specified, controlling exactly which method names are returned:
-
- -all
-
If the -all flag is given, the list of methods will include those
methods defined not just by the object, but also by the object's class and
mixins, plus the superclasses of those classes.
- -private
-
If the -private flag is given, the list of methods will also include
the private (i.e. non-exported) methods of the object (and classes, if
-all is also given).
- info object mixins object
-
This subcommand returns a list of all classes that have been mixed into the
object named object.
- info object variables object
-
This subcommand returns a list of all variables that have been declared for
the object named object (i.e. that are automatically present in the
object's methods).
- info object vars object ?pattern?
-
This subcommand returns a list of all variables in the private namespace of
the object named object. If the optional pattern argument is
given, it is a filter (in the syntax of a string match glob pattern)
that constrains the list of variables returned.
CLASS INTROSPECTION
The following subcommand values are supported by info class:
- info class constructor class
-
This subcommand returns a description of the definition of the constructor of
class class. The defintion is described as a two element list; the first
element is the list of arguments to the constructor in a form suitable for
passing to another call to proc or a method defintion, and the second
element is the body of the constructor. If no constructor is present, this
returns the empty list.
- info class definition class method
-
This subcommand returns a description of the definition of the method named
method of class class. The defintion is described as a two element
list; the first element is the list of arguments to the method in a form
suitable for passing to another call to proc or a method defintion, and
the second element is the body of the method.
- info class destructor class
-
This subcommand returns the body of the destructor of class class. If no
destructor is present, this returns the empty string.
- info class filters class
-
This subcommand returns the list of filter methods set on the class.
- info class forward class method
-
This subcommand returns the argument list for the method forwarding called
method that is set on the class called class.
- info class instances class ?pattern?
-
This subcommand returns a list of instances of class class. If the
optional pattern argument is present, it constrains the list of returned
instances to those that match it according to the rules of string match.
- info class methods class ?options...?
-
This subcommand returns a list of all public (i.e. exported) methods of the
class called class. Any of the following options may be
specified, controlling exactly which method names are returned:
-
- -all
-
If the -all flag is given, the list of methods will include those
methods defined not just by the class, but also by the class's superclasses
and mixins.
- -private
-
If the -private flag is given, the list of methods will also include
the private (i.e. non-exported) methods of the class (and superclasses and
mixins, if -all is also given).
- info class mixins class
-
This subcommand returns a list of all classes that have been mixed into the
class named class.
- info class subclasses class ?pattern?
-
This subcommand returns a list of direct subclasses of class class. If
the optional pattern argument is present, it constrains the list of
returned classes to those that match it according to the rules of string
match.
- info class superclasses class
-
This subcommand returns a list of direct superclasses of class class in
inheritance precedence order.
- info class variables class
-
This subcommand returns a list of all variables that have been declared for
the class named Iclass (i.e. that are automatically present in the
class's methods, constructor and destructor).
FUTURE CHANGES
Note that these commands are likely to be renamed in the future.
EXAMPLES
Every object necessarily knows what its class is; this information is
trivially extractable through introspection:
-
oo::class create c
c create o
puts [info object class o]
-> prints "::c"
puts [info object class c]
-> prints "::oo::class"
The introspection capabilities can be used to discover what class implements a
method and get how it is defined. This procedure illustrates how:
-
proc getDef {obj method} {
if {$method in [info object methods $obj]} {
# Assume no forwards
return [info object definition $obj $method]
}
set cls [info object class $obj]
while {$method ni [info class methods $cls]} {
# Assume the simple case
set cls [lindex [info class superclass $cls] 0]
if {$cls eq {}} {
error "no definition for $method"
}
}
# Assume no forwards
return [info class definition $cls $method]
}
SEE ALSO
oo::class(n), oo::define(n), oo::object(n), self(n)
KEYWORDS
introspection, object
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- OBJECT INTROSPECTION
-
- CLASS INTROSPECTION
-
- FUTURE CHANGES
-
- EXAMPLES
-
- SEE ALSO
-
- KEYWORDS
-
This document was created by
man2html,
using the manual pages.
Time: 03:12:19 GMT, April 23, 2009