Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: wishlist: static analysis of perl modules

by dash2 (Hermit)
on Feb 23, 2003 at 17:46 UTC ( [id://237913]=note: print w/replies, xml ) Need Help??


in reply to Re: wishlist: static analysis of perl modules
in thread wishlist: static analysis of perl modules

True. As I said, I wouldn't expect this code to understand stuff like evals. Just to get the vanilla stuff.

Actually, the request for "static" wasn't because I really can't run the program. It was more to direct people's attention away from runtime characteristics of the code, and towards the structure of the code. For example, finding subroutines which never get called (I assume that trying to do this at runtime would involve us in the halting problem :-)

dave hj~

Replies are listed 'Best First'.
Re: Re: Re: wishlist: static analysis of perl modules
by zengargoyle (Deacon) on Feb 23, 2003 at 18:53 UTC

    if you're rather consistant in your coding style (or maybe after a run through perltidy) and you're familiar with the way the code is constructed then it seems you could do some of what you want with simple text processing.

    just grep for /sub/ and build a list of your named subroutines, then grep for the subroutine names on lines that don't match /sub/.

    i've been planning to look at perltidy's source for ideas along the same lines as your question. i figure if perltidy can grok perl enough to colorize and format perl nicely then it might be easy enough to make it do other transformations on the code. i'd like to be able to do something like:

    package F; my %D = ( foo => 1 ); sub new { my ($c,%p) = @_; my %s = ( %D, %p ); return bless \%s, $c; } sub f_1 { my $s = shift; ... } package main; my $f = new F; print $f->f_1('blah');

    and then be able to generate a transform file.

    F -> Foo %D -> Default &new $c -> class %p -> parameter %s -> self &f_1 -> marble $s -> self main $f -> foo_obj

    and then be able to swap back and forth. most of the stuff i need to get done deals with tight name domains, and by that i mean that:

    j is a jack h is a host ac is an account t is a topology p is a port v is a vlan n is a netmask b is a building r is a room m is a MAC address

    it doesn't confuse me at all, might be because i started BASIC back in the early Apple II days when you could only use single character variables, and the days of Fortran where the initial character represented int/float, or maybe because i was a physic major and they'll go into foreign characters before they'll use longer varibles.

    but i realize that for the people who look at my code when i'm done just see noise unless the variables are longer.

    once the code is actually written i don't have a problem with the names being long, i just haven't found a better way as of yet than manually (vim, so it isn't that hard =)

      Interesting. Have you looked at Class::MakeMethods? It has quite powerful methods for method generation, although I suspect it only really pays for itself when you are writing a lot of classes.

      dave hj~

Re: Re: Re: wishlist: static analysis of perl modules
by seattlejohn (Deacon) on Feb 23, 2003 at 23:33 UTC
    I wanted to second zengargoyle's comment above (++). If you restate the problem as finding subroutines which are never mentioned, as opposed to called, you could do various grep-type searches. Of course, Perl's complex syntax makes it difficult to identify even mentions of subroutines with real precision. If you have a sub called add, for example, you need to know that print "add" is not a subroutine call, but that print "@{[ add ]}" is.)

    As for edit my code and change names of a variable or subroutine, wherever it's referred to... well, I admit I typically use a low-tech solution in my editor called "search and replace" :-)

    To warn me about private subroutines (sub _foo) being called from outside their class/subclasses: Seems like you could insert a line at the beginning of the private sub that would check UNIVERSAL::isa to see if the calling object is a descendant of the appropriate type.

    And finally, increase my attractiveness to women. I am inclined to respond that "I have discovered a truly remarkable technique which this textbox is too small to contain." (With tongue firmly in cheek, and copious apologies to Pierre de Fermat.)

            $perlmonks{seattlejohn} = 'John Clyman';

      I am inclined to respond that "I have discovered a truly remarkable technique which this textbox is too small to contain."

      "technique"? that's a new word for it (woof woof)

      look what's bursting out of his textbox (fnarr fnarr)

      dave hj~

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://237913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found