Perl OO code browser? 
Author Message
 Perl OO code browser?

Say I have a bunch of classes together with some tests and scripts.  I
want to see where the method Foo::Bar::stringify is called (or might
be called), but of course many classes define a `stringify' method, so
just searching for that identifier won't cut it.

I know that you can do things like

    $func = <>;
    chomp($func);
    $obj->$func('foo');
    # I wonder if this is correct Perl at all.  But
    # I'm sure that you can replace this with the correct
    # Perl in your mind.  I'm after something which reads a
    # method name from <> then calls the function of that
    # name.

and clearly nobody knows (at least without knowing the input) whether
this will call stringify or not.  But it would be okay to either flag
these spots as potential calls of stringify, or maybe to omit them
altogether.

Thousands of people must have had the same problem, so surely there
are solutions out there.

kai
--
I like BOTH kinds of music.



Mon, 03 May 2004 00:31:48 GMT  
 Perl OO code browser?
Hi all,

I started work on one some time back using
Perl/Tk. Got a reasonable way down the road
such that a folder view of classes in a
left pane could be expanded in the right
pane into actual code, and that items
clicked on would show the classes inherited
from or used. (so you could trace the hierarchy
as you were indicating.)

Didn't complete it owing to other calls on my
time, but I'd be interested to know
what the demand would be.

Kind regards

Derek.

Quote:
> -----Original Message-----

> Behalf Of Kai Gro?johann
> Sent: 14 November 2001 11:32

> Subject: Perl OO code browser?

> Say I have a bunch of classes together with some tests and scripts.  I
> want to see where the method Foo::Bar::stringify is called (or might
> be called), but of course many classes define a `stringify' method, so
> just searching for that identifier won't cut it.

> I know that you can do things like

>     $func = <>;
>     chomp($func);
>     $obj->$func('foo');
>     # I wonder if this is correct Perl at all.  But
>     # I'm sure that you can replace this with the correct
>     # Perl in your mind.  I'm after something which reads a
>     # method name from <> then calls the function of that
>     # name.

> and clearly nobody knows (at least without knowing the input) whether
> this will call stringify or not.  But it would be okay to either flag
> these spots as potential calls of stringify, or maybe to omit them
> altogether.

> Thousands of people must have had the same problem, so surely there
> are solutions out there.

> kai
> --
> I like BOTH kinds of music.

_________________________________________________________
Do You Yahoo!?



Mon, 03 May 2004 16:38:36 GMT  
 Perl OO code browser?
UNIVERSAL::can will tell you if an object can call a method (either
directly or via inheritance).

    $func = <>;
    chomp($func);
    if (UNIVERSAL::can($obj, $func) {
      $obj->$func->('foo');
    }

Does this help?

--
  Simon Oliver



Mon, 03 May 2004 19:35:16 GMT  
 Perl OO code browser?

Quote:

> UNIVERSAL::can will tell you if an object can call a method (either
> directly or via inheritance).  [...]  Does this help?

No, this does not help.  I have a situation like the following:

    package foo;
    sub xx {...}

    package bar;
    sub xx {...}

    # more packages with sub xx omitted

And then I have various (many!) places in the code where it says

    $a->xx(...);

Now, the question is: which of those places call foo::xx (rather than
bar::xx or yet another method)?

The reason I'm asking is that I might have changed the behavior of
foo::xx and so I need to change all callers.

To make this a bit simpler, I have tried to write my methods like
this:

    sub {
        my foo $self = shift;
        my bar $other = shift;
        ...
    }

And from this, one can guess that $other->xx means bar::xx and not
foo::xx.  But it was not so easy to do this everywhere, so...

Do you understand my problem now?

kai
--
I like BOTH kinds of music.



Mon, 03 May 2004 23:46:40 GMT  
 Perl OO code browser?
[A complimentary Cc of this posting was sent to
Kai =?iso-8859-1?q?Gro=DFjohann?=

Quote:
>     sub foo::xx {...}
>     sub bar::xx {...}
>     $a->xx(...);
> Now, the question is: which of those places call foo::xx (rather than
> bar::xx or yet another method)?

Just use DWIM.pm.  Or start your brower with

  use solve 'Halting::Problem';

Quote:
>         my foo $self = shift;
>         my bar $other = shift;
> And from this, one can guess that $other->xx means bar::xx and not
> foo::xx.

Depends on the ISA hierarchy - but this is not that important, since
probably you know it in advance.

Ilya



Tue, 04 May 2004 05:06:56 GMT  
 Perl OO code browser?

Quote:

> I started work on one some time back using Perl/Tk. Got a reasonable
> way down the road such that a folder view of classes in a left pane
> could be expanded in the right pane into actual code, and that items
> clicked on would show the classes inherited from or used. (so you
> could trace the hierarchy as you were indicating.)

Hm.  This seems to show me all method definitions.  (I have something
like this already; using Emacs and doing M-x speedbar RET on the
directory in question.)

But I have a method call and I'm looking for the corresponding method
definition.  This is not so simple.

kai
--
I like BOTH kinds of music.



Wed, 05 May 2004 04:51:56 GMT  
 Perl OO code browser?
Kai,

Quote:

> > I started work on one some time back using Perl/Tk. Got a reasonable
> > way down the road such that a folder view of classes in a left pane
> > could be expanded in the right pane into actual code, and that items
> > clicked on would show the classes inherited from or used. (so you
> > could trace the hierarchy as you were indicating.)
> Hm.  This seems to show me all method definitions.  (I have something
> like this already; using Emacs and doing M-x speedbar RET on the
> directory in question.)

> But I have a method call and I'm looking for the corresponding method
> definition.  This is not so simple.

> kai

Umm, not quite.

The aim was to have it capable of exactly what you said,
i.e. show the inheritance tree from a given method
invocation, in addition to allowing one to browse the
class(es) that it (they) came from, and show the actual
method called. I had understood this aspect was what
you were looking for.

In any case, I'm wondering still what the call
would be for a proper class browser like this.

Kind regards

Derek.

------------------------------------------------------
Derek Jones                      1051, Bollinger Road,
Tel:    717 359 8817                      Littlestown,
Mobile: 717 977 4556                    PA, 17340, USA

AIM:   scunacc

_________________________________________________________
Do You Yahoo!?



Wed, 05 May 2004 06:28:46 GMT  
 Perl OO code browser?

Quote:

> The aim was to have it capable of exactly what you said, i.e. show
> the inheritance tree from a given method invocation

Ah, nice.  But how does one find out which method is being called?
That would be interesting to know for me, as a Perl newbie.

kai
--
I like BOTH kinds of music.



Wed, 05 May 2004 06:57:54 GMT  
 Perl OO code browser?

Quote:


>> No, this does not help.  I have a situation like the following:

>>     package foo;
>>     sub xx {...}

>>     package bar;
>>     sub xx {...}

>>     # more packages with sub xx omitted

>> And then I have various (many!) places in the code where it says

>>     $a->xx(...);

>> Now, the question is: which of those places call foo::xx (rather than
>> bar::xx or yet another method)?

> all you have to do is know what class $a is blessed into (via print
> ref($a))

Hm.  So, if I want to know where does foo::xx get called, I search
the code for invocations of some method/function named xx.  Then I
write a script which figures out what is the object to the left of
"->" and then frobs the Perl source such that it prints ref(<object>)
before the call.  And then I start a test script that tries to make
sure that all the possible paths through the code (or at least all
the paths involving xx) are actually taken.

Whee.  Sounds like a lot of work.  Of course, the most difficult part
is writing the test script that makes sure to execute all code paths.

I was hoping that there was a static analysis method which was less
involved...  Specifically, with the approach that you are suggesting,
I need to do work after every code change (make sure that there is a
test script).

Is it not possible to do better?

kai
--
I like BOTH kinds of music.



Wed, 05 May 2004 04:50:24 GMT  
 Perl OO code browser?
[snip]

Quote:
> Is it not possible to do better?

Change the definition of each sub named xx such that it prints out
information about it's caller.  The caller() sub should help a bit.

--
Klein bottle for rent - inquire within.



Fri, 07 May 2004 11:33:53 GMT  
 Perl OO code browser?

Quote:


> > The aim was to have it capable of exactly what you said, i.e. show
> > the inheritance tree from a given method invocation
> Ah, nice.  But how does one find out which method is being called?
> That would be interesting to know for me, as a Perl newbie.

The "m" command in the de{*filter*} does this; or rather prints a list of
all methods for a class.

Ian



Fri, 07 May 2004 18:23:39 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Cache Intersystems

2. need help organizing perl oo code.

3. problem with OO code in a Safe

4. C-Scope: A Mini C Code Browser Written In Perl

5. Return Code From Perl itself & from Browser

6. PERL code in browser instead of page

7. PERL code in browser instead of page

8. C-Scope: A Mini C Code Browser Written In Perl

9. Telnet Unit

10. 5 Common Mistakes

11. TCS'99 -- CALL FOR PAPERS

12. Delphi 3 - Access / Bypass

 

 
Powered by phpBB® Forum Software