Oh holders of Perl wisdom, this humble programmer seeks to know if a very nice feature of statically-typed languages is somehow possible in Perl: compile-time checking of the existance of class methods.

My problem: class hierachies sometimes need to be changed. This can include renaming/moving of packages, renaming of methods, and changing method parameter requiries. In statically-typed languages this is a relatively easy process, because the compiler will tell me if I have forgotten to change a method call somewhere - the incorrect method just doesn't exist in that class.

This leads to very nice features in IDEs like Netbeans, where simple renaming of classes, methods, or variables can be totally automated. Moreover, if I change the method prototype/parameter list, the IDE just tells me where I have to correct the calls, and I can correct my code quickly.

With a dynamically typed language like Perl, I assume this is very difficult to automate.

My question: Are there Perl tools that can automatically rename classes and methods, or even just display where I used a specific class or method name in an object? find|grep just doesn't cut it if a method name is too generic. Even worse, if I forget changing a method call, this will only become apparent at runtime, or if I have written enough tests. When I work on an existing project without tests, a simple perl -c is just not enough to check for such errors.

I realize such a tool is not easy to program, because method declarations are not only found in the source, but methods can be created at runtime (e.g. automated accessor method creation). Perhaps there is a tool/module that can collect package method names during runtime, and use that information to analyze the source and tell me where I called a method for which no declaration can be found?

Whenever I switch from a Java project to a Perl project, this problem arises. I forget to check for stuff in Perl that javac does automatically for me. I realize this is not a fault of Perl, but a result of the dynamic typing paradigm. But I have to switch languages from time to time, and would like to have more fun with Perl.

In reply to Compile-time/Auto-test method checking? by Cybris

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.