Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Reflection or discovery of object methods in perl?

Reply
Thread Tools

Reflection or discovery of object methods in perl?

 
 
Guest
Posts: n/a
 
      11-09-2004
hello!

again i am trying to get some stuff working (this time CORBA...), and again
i would need an inspection tool telling me what class an object is
and what methods its possesses...

i know UNIVERSAL::can but that one expects a method name, it doesn't spit
out the whole list when not provided with a method name...

so is there that type of mechanism in perl?

thanks
--
bboett at inforezo dot u-strasbg dot fr
http://inforezo.u-strasbg.fr/~bboett
================================================== ============
Unsolicited commercial email is NOT welcome at this email address
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      11-09-2004
<> wrote in comp.lang.perl.misc:
> hello!
>
> again i am trying to get some stuff working (this time CORBA...), and again
> i would need an inspection tool telling me what class an object is
> and what methods its possesses...


The class is easy: perldoc -f ref. Finding all methods can't be done.

One could (conceivably) walk the symbol table of the class and extract
all coderefs (plus, recursively, the classes on @ISA). But there is
no way of telling if a sub is a public method (or a method at all),
so you'd get a lot of garbage besides the actual methods, and no
way to tell one from the other.

Anno
 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      11-09-2004
In article <cmq9lh$3u2$>,
Anno Siegel <> wrote:
>The class is easy: perldoc -f ref. Finding all methods can't be done.

hmmm pity....

>One could (conceivably) walk the symbol table of the class and extract
>all coderefs (plus, recursively, the classes on @ISA). But there is
>no way of telling if a sub is a public method (or a method at all),
>so you'd get a lot of garbage besides the actual methods, and no
>way to tell one from the other.

ok! where do i find those symbol tables?

--
bboett at inforezo dot u-strasbg dot fr
http://inforezo.u-strasbg.fr/~bboett
================================================== ============
Unsolicited commercial email is NOT welcome at this email address
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      11-09-2004
<> wrote in comp.lang.perl.misc:
> In article <cmq9lh$3u2$>,
> Anno Siegel <> wrote:
> >The class is easy: perldoc -f ref. Finding all methods can't be done.

> hmmm pity....
>
> >One could (conceivably) walk the symbol table of the class and extract
> >all coderefs (plus, recursively, the classes on @ISA). But there is
> >no way of telling if a sub is a public method (or a method at all),
> >so you'd get a lot of garbage besides the actual methods, and no
> >way to tell one from the other.

> ok! where do i find those symbol tables?


In perldata, perlmod and perlsub, mainly.

Here is an example that lists all subs in main (scratch the "grep"
to see all symbols):

sub foo {} # define a sub, or you won't see much
print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::

You'll have to use some nasty symrefs to make it use an arbitrary
string instead of "main". That is one of the cases where symrefs
are officially tolerated.

Anno
 
Reply With Quote
 
Guest
Posts: n/a
 
      11-09-2004
In article <cmqd0j$67n$>,
>Here is an example that lists all subs in main (scratch the "grep"
>to see all symbols):
>
> sub foo {} # define a sub, or you won't see much
> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::

interesting i was planning to use the 'can' method to achieve the same
anyway thanks a lot!

making myself an inspection class

ciao
Bruno
--
ciao
Bruno

Bruno.Boettcher at visualsphere dot com
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      11-09-2004
>>>>> "AS" == Anno Siegel <> writes:

AS> Here is an example that lists all subs in main (scratch the "grep"
AS> to see all symbols):

AS> sub foo {} # define a sub, or you won't see much
AS> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::

AS> You'll have to use some nasty symrefs to make it use an arbitrary
AS> string instead of "main". That is one of the cases where symrefs
AS> are officially tolerated.

as my rule states, use symrefs only when you are munging (which covers
searching the symbol table.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      11-09-2004
>>>>> "B" == <> writes:

B> In article <cmqd0j$67n$>,
>> Here is an example that lists all subs in main (scratch the "grep"
>> to see all symbols):
>>
>> sub foo {} # define a sub, or you won't see much
>> print "$_\n" for grep defined( &{ $main::{ $_}}), keys %main::


B> interesting i was planning to use the 'can' method to achieve
B> the same anyway thanks a lot!

how would you use can() for introspection? you would have to search all
possible strings and run can() on them.

also with AUTOLOAD you can't fully tell what methods are there. autoload
can handle any method, or decide what is available at run time or
whatever. i find the concept of introspection to be weak and not needed
much. but others seems to live on it. either you know the classes you
want or you don't.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Guest
Posts: n/a
 
      11-09-2004
In article <>,
Uri Guttman <> wrote:
>how would you use can() for introspection? you would have to search all
>possible strings and run can() on them.

yep that's what i do, spares one eval statement...
that way i can separate also what are variables...

BTW a chance to easily try to extrapolate what return type the subs
might have (means without actually executing them...)?

>also with AUTOLOAD you can't fully tell what methods are there. autoload
>can handle any method, or decide what is available at run time or

sure...
but not in my code

>whatever. i find the concept of introspection to be weak and not needed
>much. but others seems to live on it. either you know the classes you
>want or you don't.

well in most cases yes, when you are debugging a non working CORBA
framework (at least non working for me...) with perl objects that have no
(or nearly no) documentation, it can come in quite handy...

ciao
Bruno

Bruno.Boettcher at visualsphere dot com
================================================== ============
Unsolicited commercial email is NOT welcome at this email address
--
ciao
Bruno

Bruno.Boettcher at visualsphere dot com
 
Reply With Quote
 
Peter Scott
Guest
Posts: n/a
 
      11-09-2004
In article <cmq8q7$fcq$>,
() writes:
>again i am trying to get some stuff working (this time CORBA...), and again
>i would need an inspection tool telling me what class an object is
>and what methods its possesses...
>
>i know UNIVERSAL::can but that one expects a method name, it doesn't spit
>out the whole list when not provided with a method name...
>
>so is there that type of mechanism in perl?


http://search.cpan.org/dist/Class-Inspector/lib/Class/Inspector.pm#methods_$class,_@options

--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
 
Reply With Quote
 
Guest
Posts: n/a
 
      11-09-2004

Hi!

another problem rose now....

uhm might seem stupid, but the ISA array is available only inside the
objects themselves, seems i can't acces them from the outside...

any way to get a hold of the super classes of an object?


--
ciao
Bruno

Bruno.Boettcher at visualsphere dot com


--
ciao
Bruno

Bruno.Boettcher at visualsphere dot com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
How do you get feed discovery to work? I go to web pages I know has feeds, but the feed discovery button is disabled. Help! Tim Bryant Computer Support 1 02-13-2007 05:01 AM
How to Invoke Methods by Name using JAVA reflection imran Java 1 02-01-2005 01:00 PM
Using the Reflection API to dynamically modify methods Serge Java 7 02-17-2004 07:11 PM
dynamic method call using reflection only works with certain methods? Soefara Java 2 08-20-2003 06:00 PM



Advertisments