It is pretty hard to write a code completion script for perl since it’s hard to find out of which type a variable is. I use simple regexes and a comment to achieve this. Here is how it looks like:
It consists of a perl script which reads the current file from STDIN and gets the current line number as well as the cursor position in that line. The script is run if the cursor is behind a -> and the string before that looks like a class or a variable. If it’s a variable the script travels the lines up until it finds something like $var = Class->new, $var = new Class or # $var isa Class.
Class::MOP::Class loads that class and retrieves all method names. It also evaluates the prefix which has been entered behind the -> and displays those methods only which have the same prefix. Private methods are moved to the buttom as well as capitalized method names.
The second part of this script is embedded in TextMate. TextMate allows to define custom commands. You can define how the data shoud be rendered depending on the return value of the script. In this case STDERR is printed directly into the editor (if there is only one method left) and STDOUT is printed as tool tip.
I’d like to hear what you think about it and whether there are better / other approaches. I should probably use PPI instead of regexes to parse the document. This is one of the reasons why I did not release any code yet. Another shortcoming is speed. Especially for large classes like Catalyst or DateTime it takes a noticeable time until you get the results.
So long… I’ll keep you posted.
TextMate has a number of great bundles which help you develop in many many languages. The feature I miss most is formatting for JavaScript just like Perl Tidy does it for Perl.
I recently saw JavaScript::Beautifier in the “Recent” list on the CPAN and was wondering if I can bind it to TextMate. This is how I did it:
First of all, install it:
sudo cpan -i JavaScript::Beautifier
Next, add the command to TextMate. Open the Bundle Editor (Bundles/Bundle Editor/Show Bundle Editor).

Then select JavaScript and click on “New Command” (bottom left).
Name it “Beautifier” (or whatever you want) and paste the following in the command text field:
require_cmd js_beautify.pl 'sudo cpan -i JavaScript::Beautifier' js_beautify.pl $TM_FILEPATH
Set the rest of the options like this:
Now you are ready to go! Open up a JavaScript document and hit Shift+Crtl+H and the current document should be formatted.
