Re: Compile-time/Auto-test method checking?
by perrin (Chancellor) on Jun 26, 2009 at 15:09 UTC
|
| [reply] |
Re: Compile-time/Auto-test method checking?
by mzedeler (Pilgrim) on Jun 26, 2009 at 12:37 UTC
|
| [reply] |
|
|
Most likely using the generic out of the box solution: ctags!
| [reply] |
Re: Compile-time/Auto-test method checking?
by Anonymous Monk on Jun 26, 2009 at 08:56 UTC
|
| [reply] |
|
|
Thanks, this helps for renaming packages/classes. What about methods?
| [reply] |
Re: Compile-time/Auto-test method checking?
by ELISHEVA (Prior) on Jun 26, 2009 at 13:13 UTC
|
It isn't the perfect solution, but my best friend when it comes to changing parameter list and/or renaming Perl methods is the bash command:
find ... -print0 | xargs -0 grep 'mymethodname'
-or-
find ... -print0 | xargs -0 grep -l 'mymethodname'
I use the first when I want to find all the files and lines containing my method name. I use the second when I just want to see which files have such lines. If you aren't familiar with the commands:
- find recursively searches for files. It has a rich set of options you can use to screen out files you aren't interested in. The -print0 option uses the null character to separate file names so you don't have to worry about quoting file names with spaces.
- xargs passes the file list produced by find to grep. The -0 argument tells xargs to expect a null delimited file list.
- grep - most likely you are familiar with this, but it selects lines containing a regex you provide. If you only want to see the file names, but not the lines, use the -l option.
With all the find options, the command line can be quite long so I usually run it in a shell where I can keep history. That way I can simply recall the command via history, changing the method name as needed.
Best, beth | [reply] [d/l] [select] |
Re: Compile-time/Auto-test method checking?
by LanX (Saint) on Jun 26, 2009 at 13:28 UTC
|
The only¹ static approach I can think of is to restrict/enrich an object model in a way to define the methods statically.
That means you can extend each class you use with information (eg an array or flagging them with attributes) about the method names.
Then you can get the information which classes use which methods without running the class-code.
Well you can easily do this with your own code... and I suppose you don't plan changing method names of foreign classes...
BUT then you still have the problem to identify statically which class an object belongs to. An object in Perl is just a blessed reference to a data structure. A reference might have been created from somewhere without any "new class" syntax in the same file to parse.
So you have to enrich your code with type-declarations (should be possible with attributes)
So it's possible (you will be mimicking the mechanisms of static languages) but is this still perl???
There are plenty of discussions of this in Perlmonks (search for static parsing and ppi), you might want to check if IDE-extensions like perlysense for emacs or padre already provide any automated help.
UPDATE: (1) reliable | [reply] |
|
|
| [reply] |
|
|
> Module::Inspector, Class::Inspector
well yes, AFAIK these are ppi spin-offs and Gabor's approach for padre.
But if the OP is only talking about self-written classes and compares to java he might be happy about a robust attribute¹ based solution instead of relying on ppi's "guessing what the author meant".
BTW: How do these modules handle AUTOLOAD?
UPDATE: (1) Attribute::Handlers
| [reply] |
Re: Compile-time/Auto-test method checking?
by CountZero (Bishop) on Jun 26, 2009 at 20:24 UTC
|
Moose with its powerful meta and introspection methods and Class::MOP (on which Moose is based] go a long way in doing what you need, I think. However, they are all run-time and not compile-time tools.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] |
Re: Compile-time/Auto-test method checking?
by educated_foo (Vicar) on Jun 26, 2009 at 16:58 UTC
|
If you use Emacs, check out find-grep-dired and dired-do-query-replace-regexp. It's not completely automatic, but still eases the pain. | [reply] [d/l] [select] |
Re: Compile-time/Auto-test method checking?
by Anonymous Monk on Jun 26, 2009 at 12:33 UTC
|
not exactly a solution, just a comment..
about a year ago I heard someone was trying to add perl support in netbeans, have you searched for this already ? perhaps they made it. | [reply] |