develooper Front page | perl.perl6.language | Postings from July 2005

Subroutine and Method Introspection

Thread Next
July 20, 2005 21:04
Subroutine and Method Introspection
Message ID:
A12 and S12 describe introspection on objects and classes.  The
metaclass instance has the method getmethods() which returns "method
descriptors".  The design specifies several traits queryable through
these descriptors.

Methods (and subroutines) can take other traits, such as "is lvalue" or
even user-defined traits.  I can imagine that a Perl 6 port of
Test::Class would suggest using trats of "is startup" and "is
tests( 4 )" to replace the use of attributes in the Perl 5 version.

Currently, there's no way to query these traits through introspection,
nor is there a description of the descriptors beyond indicating that
they're some sort of object.

I have no strong feeling as to what type of object they should be, but
they ought to support some sort of traits() method to return a list of
names of all available traits on the method.  Passing the name of a
trait to the method ought to return the value of the trait, if it is a
parametrized trait.  Otherwise, it could return boolean.

Perhaps there's a more general mechanims that works better in specific
cases.  Ruby's Class#method? syntax is nice, but being able to hardcode
a method name and pass a string parameter makes introspection a little
more automable.

Having the class for these descriptors be available and extensible also
makes it possible to write a method that returns only the *interesting*
traits, which might be convenient.


-- c

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About