Archive for August, 2007

Why I wrote Perl Console (or why I don’t use perl -e 1 -d)

Since Perl Console has been released, I received a couple of mails from random people asking me what were the differences between my console and the internal Perl debugger (that is accessible with `perl -e 1 -d`).

Here is a common answer to that question (so I won’t have to write again and again the same mail).

Q: What are the specials features in your solution that are not in ‘perl -e 1 -d’ ?

A: First of all, it’s clearly more user-friendly as it provides completion with variable names and module’s symbols and saves your history in ~/.perlconsole_history. You have all the Term::Readline goodness with the console, which is a major improvement when you use the console all day for testing your code, writing Perl modules or even writing unit-tests.

Second (the most important part to me), Perl Console is a Read-Eval-Print-Loop. “perl -e 1 -d’ is not : it does not prints out your results if you don’t tell it to.

Here is a short example that speaks by itself:

$ perl -e 1 -d
[..]
main::(-e:1):   1
  DB<1> 1 + 1

  DB<2> ^D

$ perlconsole
Perl Console 0.3+svn

Perl> 1+1
2

Perl>

Having always the result of your expression without needing to ask for it is, to me, a major improvement. And that’s what a REPL program is supposed to do.

One major difference between those two environments is about the namespace. In Perl Console all your code is evaluated under the strict mode. Meaning all your commands have to be “use strict” valid. You cannot use $foo if $foo wasn’t declared before with a “my”. In Perl Console, everything declared with my is saved in the console’s namespace. That’s not the case with the debugger which has one namespace by line. Let me prove this:

  DB<1> my $foo = 42

  DB<2> print "foo: $foo"
foo:
  DB<3> $bar = 84

  DB<4> print "bar: $bar"
bar: 84

As you can see, in the debugger, variables declared with “my” are not in the scope of other commands. In Perl Console, they are (and you cannot use undeclared variables as you are in scritct mode, which is good) :

Perl> my $foo = 42
42

Perl> $foo
42

Perl> $bar = 84
[!] compilation error: Global symbol “$bar” requires explicit package name at (eval 9) line 4.

You can also load any module you like within the console and each of these modules will be refreshed transparently if they changed on disk. That’s more than useful when you write a module and test it with the console (you don’t have to quit the console to get the changes applied).

Moreover, Perl Console provides different output modes, you can choose the one you like between Data::Dumper, YAML, Data::Dump and Data::Dump::Streamer (in version 0.3).

Let’s take a look at some output modes:

Perl> :set output=scalar

Perl> my $hash = {foo => 1, bar => 2, baz => 4}
HASH(0x83a52a0)

Perl> :set output=dumper

Perl> $hash
$VAR1 = {
'bar' => 2,
'baz' => 4,
'foo' => 1
};

Perl> :set output=yaml

Perl> $hash
---
bar: 2
baz: 4
foo: 1

Perl>

The console can also source a startup script if you like to load a module for instance and define a couple of variables you like to have in your test sessions : perlconsole –rcfile ~/.perlconsole-myproject for instance.

To conclude, it’s far more user-friendly and powerful than the perl internal debugger and is designed to be your all-day companion for testing strict code.

Comments

Perl Console 0.3 released

A new version of PerlConsole is available. As you can see in the changelog, lots of goodness with this release comes to you (~/.perlconsolerc rules, thanks to S. Zachariah Sprackett for his patch).

After reading the source code of Devel::REPL and learning from it (this is really a great library, congrats to mst) I decided not to orphan Perl Console. Yes, that was a possibility as Devel::REPL provides anything you need to build a console (and comes with “re.pl” which actually is a console itself). I decided not to give it up for one reason: Devel::REPL is great, and better written than Perl Console (it supports plugins and profiles and is Moose-based) but, it’s slow.

When you launch it, you have to wait a couple of seconds before the console prompts you. This is because of Moose I suppose. I know that’s not blocker as a console is a development tool, but I feel like some of PerlConsole’s users would like to have the choice between a full featured, extensible and Moose-base console that’s slow, and a light one that is basic in design and implementation.

I backported one of the most interesting plugin of Devel::REPL to PerlConsole, being the console’s lexical environement. Devel::REPL did a great thing there, using Lexical::Persistence to simulate a namespace in the console.

Feel free to give your feedback about this, I wonder if there’s still an audience for PerlConsole when Devel::REPL is in the town. I think so, maybe I’m wrong, then tell me.

Comments

The road to libdevel-repl-perl, part 2

Thanks to Florian Ragwitz, who packaged libpadwalker-perl 1.5-1, there is no blocker anymore that prevents libdevel-repl-perl from entering sid:

By the way, the author of Devel::REPL, Matt S Trout, looks pretty happy to see his module entering Debian.

I’ve just uploaded libdevel-repl-perl, this upload closes the exciting work session we did during all the weekend with Damyan Ivanov, in order to get the module into debian. All its dependencies are now in the Perl group’s hands. That was fun.

Team maintenance rocks!

Comments

The road to libdevel-repl-perl, part 1

I decided to play with Devel::REPL which looks to be exactly what I need to enhance my Perl Console. That module is not packaged in Debian, then I started packaging it with the help of the Debian Perl Group (big thanks go to Damyan Ivanov for his help).

The day was pretty productive and we’re almost done now, as you can see in this tomboy note:

PS MadCoder: I’m sorry dude, I’m still speaking about Perl :P

Comments

Perl Console 0.2 Debian package

The first version of the debian package of Perl Console has been uploaded to the NEW queue. For those who are waiting for it, I’ve also uploaded the package here.

Thanks to the patch sent by Antonio Terceiro, the version 0.3 will be properly packaged ala Perl (namely with the famous Makefile.PL, MANIFEST and friends).

I plan to adress the multi-line issue for 0.3 (mainly handling code with loops or conditional structures), as Florian Ragwitz underlined, it could be worth using Devel::REPL instead of rewriting the wheel.

Comments

Perl Console 0.2

Hey, version 0.2 of the Perl Console is out.

I found Gunnar’s comment in my first blog entry pretty relevant: providing only a scalar output isn’t user friendly; but freezing the console with either YAML or Data::Dumper would at best satisfy half of the user base.

Hence comes the “preferences” idea. The console allows the user to choose either a value or another for a given preference. No big deal there, but it’s clearly the best thing to do for the output issue.

In version 0.2, the user can enter something like that to change the output mode:

:set output = yaml

If the user wants to know what are the possible values for the preference “output” he can enter the following command:

:help output

Of course, the help engine reads dynamically the preferences definition, in order not to display outdated information (code changes, you know that!).

So, in short, what’s new in 0.2:

  • Complete rewrite of the program in object-oriented Perl
  • support for preferences (user can set preferences)
  • preference “output” added, with 3 values possible: scalar (default), yaml, dumper
  • help engine added

The tarball is there, next step is the debian package (ITP already sent).

Comments

Perl Console

My Perl Console now uses Term::Readline for grabbing the user input, provides completion and keybindings. Moreover it can also load dynamically a module.

Well, actually the pet program is getting older, and I could not resist to give it its own webpage. Check it out Perl developers!

Note to myself (and to other members of the Debian Perl Group) : could be very useful for debugging the modules we maintain.

Comments (6)

Back to the matrix

Hey Lazyweb.

I’m back from holydays (those two weeks spent at Marbella, Spain, were fantastic, I even managed to fix my programmer’s tan, true).

I’m back at work, which means back at Debian’s work as well. I took a tour on my QA page yesterday in order to do some cleanup in and there. I first focused on the my Perl packages. I upgraded my working copy of the Perl Group’s SVN repo, whose layout changed recently thanks to Joey Hess. All of the perl libraries I maintain are now officially handled by the team (Maintainer: Debian Perl Group, myself as an uploader).
I then came to backup-manager in order to do some bug-hunting and closed 3 of them.

Comments