February 07, 2009

Devel::REPL and Carp::REPL

Devel::REPL is an excellent addition to your toolkit. It is an interactive shell for Perl; you type in a line of Perl code and Devel::REPL will evaluate it. You can use Devel::REPL to quickly test out code or to provide a debugging shell for your applications. There are many plugins, such as simply adding color, nopasting your session to a pastebin, and even dumping each line of code with B::Concise.

Carp::REPL builds on top of Devel::REPL to make finding bugs easier. By default, when an exception is thrown, you get a shell (though you can tweak this to get a shell on any warning or test failure). You can examine and change variables, call and redefine functions, and anything else you can do with real Perl code. Carp::REPL lets you have a shell "inside" your applications with *zero* code changes required.

Matt Trout's design for Devel::REPL is worthy of study. It is a Moose library that makes heavy use of roles to provide a great deal of customization for users. Sans plugins, Devel::REPL is just about the simplest implementation of a shell, but that just means it has the greatest amount of flexibility. This final part of the talk will be case study in the design and implementation of a nontrivial Moose application.

Creative Commons License

This talk is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.