One of the finest Perl (core!) module I’ve been using lately is File::Find. With File::Find it’s possible to traverse through a directory recursively to find anything you want from it. It comes with a number of options to alter the search behavior and a custom callback has to be supplied to determine what to do with the found file. Such as adding it to a list if it meets certain criteria, computing MD5 checksums or whatever else floats your boat.
Here’s a small example I also posted some time ago on Stack Overflow.
I was looking for a way to use Perl::Tidy with Notepad++ so I can format my Perl code from within Notepad++. Luckily for me someone else already figured out how to do this properly. I just had to modify a few small things to make this work for my needs.
My environment is a Windows Vista SP2 system with Strawberry Perl 5.12.1. Thanks to Strawberry modifying the system PATH I don’t need to configure this myself. After installing Perl::Tidy I can just call the perltidy command from the command-line. But for some reason calling the perltidy directly from within NppExec doesn’t work.
First, you need a .perltidyrc, or rather on Windows a perltidy.ini. I don’t really know why this has to be different, probably because it sometimes can be a pain to create a nameless file (meaning, a file with only a extension). Here’s my perltidy.ini file which I installed under C:\Users\<USERNAME>\perltidy.ini. I’ve actually shamelessly stolen this configuration from Mojo.
So following the earlier mentioned blog post this is what I changed to make it work for me.
- Change the command-line in NppExec to the following:
perl -x -S perltidy "$(FULL_CURRENT_PATH)"
- Do the Advanced Options part
- Now create a Macro: for some reason this doesn’t work?
- Start recording
- Go to Macro > Execute your newly added perltidy macro
- Go to File > Reload from Disk
- Stop recording
- Save Macro and assign a shortcut to it
Now I wanted to be able to fire this off with a key shortcut, but I can’t add those to macro’s created with NppExec. So instead I tried to create a macro that executes the perltidy macro and then reloads the file from disk. But when executing this macro nothing happens. So if anyone has an idea to why this is I’d be glad to hear it.
For now this manual execution will work just fine. It’s just annoying that I’ll have to reload the file from disk manually.
A couple of days ago I finished reading The Definitive Guide to Catalyst which for a technical book (or any at all) I read through quite fast. I’m not going to write a full fledged review about it but I can recommend it to anyone interested in working with Catalyst. For those who don’t know it Catalyst is a web application framework written in Perl.
Although the online documentation is very good the book is a nice addition to it. It’s more than just a collection of some code examples. The chapters follow a certain thought process to write maintainable and extensible code, complete with tests and all. Common in the book is that the example code will get a rewrite later on in the chapter to reach this goal. I consider this a nice feature of the book as it shows why that refactoring was needed and is the better solution to the problem.
There are only a few small complaints I’ve got about the book. The code indentation isn’t always consistent and there are occasionally some errors in the code. But looking more at it from a conceptual kind of view it’s clear what the author intents. I also don’t really understand the choice to include Reaction in the final chapter. Documentation is scarce and it seems abandoned. I’d much rather see some Catalyst::Runtime core modules described in there, such as Catalyst::ScriptRunner (did it even exist at the time of writing?), Catalyst::Request and Catalyst::Response. I know the latter 2 are well documented, but they weren’t even mentioned in the book.
Other than that it was a great read and am glad I bought it :-).