Sunday, March 26, 2006

Net Neutrality - where are we now?

Does this sound familiar:
The battle is about who will build, own, use and pay for the high-speed data highways of the future and whether their content will be censored.
Roger Karraker wrote that in his 1991 article, "Highways of the Mind" and the article is still relevant today. Have a look.

(See also: The Communications section of The WELL gopher.)

Saturday, March 18, 2006

Perl BEGIN Blocks Considered Harmful

Adam Kennedy pointed this out to me:
  1. Create a new Perl file containing the following:

    BEGIN {
    print "hello world\n";
    }

  2. Check the syntax with

    perl -c filename

This will print hello world, even though "all" you did was compile the file.

What's going on here?

Well, BEGIN blocks get executed when Perl compiles the file.

So what?

If you run perl -c on a file that contains nasty code in a BEGIN block, you're screwed.

Consider this:
  1. You associate the filename extension .pm with a fancy Perl editor, like Komodo, or Affrus.
  2. You click on a link in your web browser.
  3. The web server redirects you to a URL for nasty_file.pm
  4. Your browser opens the associated editor and performs a"syntax check" by compiling the file
  5. The file's BEGIN block has naughty code in it...

You're screwed.

So, keep in mind that "just compiling" Perl code may actually execute the code, so, be careful!

Here's a bug report on this subject that I filed for the Eclipse/EPIC Perl IDE.

Tags: ,

Thursday, March 16, 2006

Testing if a Perl script compiles - compile_ok

A co-worker and I were pair programming a test suite the other day, and needed to test if a Perl script compiles - not a library or module but an executeable script, so the typical:
    require_ok()
use_ok()
functions provided by Test::More don't do exactly what we wanted.

The short story is that we ended up doing something like this:
  eval {
$output = `perl -c $script 2>&1`;
chomp $output;
};
is($output, "$script syntax OK", "$script compiles");
We later looked for a more general, better solution, and a colleague posted on the perl-qa mailing list, but the bottom line is that a more elegant solution still involves executing a new perl interpreter, but in a platform-independent way (perhaps using IPC::Open3 or something.) It's also likely that a better test is to ignore the output altogether and just check the return code from the compile process (the call to perl -c.)

March 18, 2006 update: Jeff Thalhammer found that a colleague Pierre Denis provides a syntax_ok method in Test::Strict that does what we want.
More update - I was prodded by Randall Schwartz to post why you should be careful when "only" compiling Perl code - see BEGIN Blocks Considered Harmful.
Tags: ,

Swimming Snake Robot

OK, ready to be creeped-out and fascinated?

http://www.hackaday.com/entry/1234000957073583/