Archive

Archive for the ‘perl’ Category

French Perl Workshop 2007

September 6th, 2007

There is going to be a Perl event in Lyon, France during November : « The French Perl Workshop 2007 ».

I’ve submitted two talks, that have been approved today:

I was thinking of a talk about the Debian packaging of Perl modules. That could be interesting to enlight how Perl libraries are packaged, how one can build his own package for a random module and so on.
This would be a talk designed for Perl developers under Debian. Would be great to do that with a member of the Debian Perl Group. If you’re interested, feel free to contact me so we can coordinate our efforts.

Other talks are listed on that page.

Debian, perl

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

August 29th, 2007

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.

perl

Perl Console 0.3 released

August 28th, 2007

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.

Debian, perl

The road to libdevel-repl-perl, part 2

August 19th, 2007

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!

Debian, perl

The road to libdevel-repl-perl, part 1

August 17th, 2007

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

Debian, perl

Perl Console 0.2 Debian package

August 16th, 2007

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.

Debian, perl, perlconsole

Perl Console 0.2

August 13th, 2007

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).

Debian, perl

Perl Console

August 10th, 2007

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.

Debian, perl

My Perl Console

June 13th, 2007

Here is a basic Perl loop that waits for an input, evaluates it and prints out the result.

The script is utterly simple but might be useful for Perl developers.
Launch console.pl and test your code, interactively, it’s quick and efficient.

perl

Logger::Syslog, my first CPAN-candidate Perl module

November 17th, 2006

I wrote a Perl module a couple of years ago, and got used to it, I just cannot code without that module now.

It’s called Logger::Syslog and is a wrapper over Sys::Syslog that lets you deal with syslog in a very simple manner. Use the module and enjoy the easiness of calling info(), warning(), error() or whichever Syslog message level you like, there is a function wrapping it.

It also works properly under a mod_perl environment an logs your message with additional information coming from the Perl stack (module, function name, line number, …).

I use that module quite everywhere I use Perl : at work but also in my Free Software projects, like Backup Manager. It’s really time to release an “official” version that I can rely on in the future.

Next step is submitting the module to the CPAN (it’s pending) and then, debianize upload the Debian package so backup-manager can depend on it.

Todo: set up a public SVN repo to handle the sources.

Updates

Debian, perl