Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

samtregar (2699)

  (email not shown publicly)

Journal of samtregar (2699)

Wednesday June 01, 2005
03:31 PM

Don't forget to test your tests

I ported a couple tests from Krang to my latest project today and it occurred to me to share them. The tests go by the ugly names 'aaa_dbcount.t' and 'zzz_dbcount.t'. Their job is to make sure that none of the other tests in our test suite are leaking data in the database.

The first script, 'aaa_dbcount.t' is roughly:

   foreach database
      open "$dbname.count.txt"
      foreach table
         print count(*) into "$dbname.count.txt"

And 'zzz_dbcount.t' is roughly:

   foreach database
      open "$dbname.count.txt"
      foreach line
         get count(*) for the table
         is($old_count, $new_count)

The tests in zzz_dbcount.t fail when a test that runs after aaa_dbcount.t doesn't clean up after itself. This prevents one run from affecting the next one which can be a very difficult bug to catch otherwise.

When a failure happens I can use the tests to narrow it down. I pick a suspect and run:

   make test TEST_FILES="t/aaa_dbcount.t t/suspect.t t/zzz_dbcount.t"

I've thought about doing something that looks at the writable areas of the filesystem too. I bet that would have caught a nasty bug in Krang that I noticed by accident recently - deleting a story deletes the published files (good) but leaves behind empty directories (bad).

So why not wrap this up as a Test:: module? I might but it's a very small amount of code and abstracting "foreach database" and "foreach table" so it'll work across DBD drivers seems hard.


Friday April 15, 2005
11:50 AM

Greasing the Meerkat

I while back I wrote about wanting a better use.perl link display in Meerkat. My solution at the time was Middleman, a configurable HTTP proxy. I ended up ditching it after it caused some extremely difficult to debug problems developing a web-app. Instead I created a little chunk of Javascript which accomplished the same thing. I attached it to a link on my tool-bar which I click every time I visit Meerkat. It works, but it's hardly ideal.

Enter Greasemonkey, a plugin for Firefox which allows you to add Javascript to a page based on a URL match. I took the Javascript I already had in my link, converted it to a Greasemonkey user-script and now I see author names in Meerkat without any effort on my part. Fantastic!

For the record, here's my user-script:

// ==UserScript==
// @name          Meerket User Names
// @namespace
// @include*
// ==/UserScript==

(function() {
    for (var x = 0; x < document.links.length; x++) {
        var l = document.links[x];
        if (l.href.indexOf('~') != -1) {
            var name = l.href.substring(l.href.indexOf('~'));
            name = name.substring(1, name.indexOf('/'));
            l.innerHTML = '[' + name + '] ' + l.innerHTML;


Monday April 04, 2005
06:18 PM

Industrial Strength Add-Ons Coming Soon to Krang

My reinvention of the Krang add-on system is well under way. The previous system was little more than convenient way to package source code that could be copied into Krang. It had upgrades and dependencies, but that was it.

The new system will allow Krang to mature into a true application development platform. Addons will be installed into their own space under addons/. This has two important advantages: 1) it will keep addons from accidently or purposefully overwriting Krang source files (and vice-versa) and 2) addons can be developed in-place under version control.

Fixing these two issues should make developing add-ons a lot more pleasant. But the new design doesn't stop there - it also brings Krangs build system to addons so they can come with their own dependencies. A new class factory system will allow add-ons to selectively extend core Krang classes without needing to alter Krang's code. Finally, Krang's left-nav area will be modularized so add-ons can register new entries without having to completely override the navigation templates.

The new system should land in Krang v1.103 sometime later this week. I'm off on a branch for now so v1.102 can get out the door without more QA.


Thursday March 24, 2005
02:57 PM

Binding keys to raise windows by name

I generally program with three windows open - Emacs, Firefox and Gnome-Terminal. I also like huge fonts so there's no way I can see the contents of all three windows simultaneously. I've gotten used to using alt-tab to cycle through them, but it's a pain. I know which one I want but I always have to look for it.

To solve this problem I wrote a script which uses wmctrl to raise a window on the current desktop by name. Here it is:

use strict;
use warnings;

my $what = shift;
die "Missing what arg." unless $what;

my $desktops = `/usr/local/bin/wmctrl -d`;
my ($active_desktop) = $desktops =~ /^(\d+)\s+\*/m;
die "Unable to determine active desktop!" unless defined $active_desktop;

my $windows = `/usr/local/bin/wmctrl -l`;
my ($id) = $windows =~ /^(0x\w+)\s+\Q$active_desktop\E\s+\w+.*\Q$what\E/m;
die "Unable to find $what on $active_desktop!" unless $id;

system('/usr/local/bin/wmctrl', '-i', '-a', $id);

I called it and call it like:

$ emacs

Then to finish the job I edited the Metacity configuration to bind Alt-e to raise Emacs, Alt-f to raise Firefox and Alt-s to raise the terminal (shell). Mission accomplished!

(Of course, all this would be much easier if Metacity supported a scripting language like Sawfish did. I miss Sawfish...)


Friday March 11, 2005
05:27 PM

Emacs mode for Test::Harness output?

I've been playing with ECB (Emacs Code Browser) today. So far I'm very impressed. It gives me three panes stacked up next to the edit windows: a project browser, a file browser and a buffer list. It will also do method browsing but I'm not ready for that yet.

The thing is, it's missing something: tests. I still have to switch to a terminal every time I run my tests. Ideally I'd like to bind a key to run 'make test' on the project and see the results in a buffer. Syntax highlighting would be icing on the cake.

Anyone know of something I can use for this? I tried M-x compile but the Test::Harness output looks horrible in it. Googling around and looking in the Emacs Wiki didn't turn up much.


Thursday March 03, 2005
07:59 PM

My book is now free!

My book, Writing Perl Modules for CPAN, is now available as a free download from Apress. Enjoy!


Wednesday March 02, 2005
12:07 PM

The Rock Moved

I got out from under my rock briefly last night, attending my second New York Perl Monger's meeting. I went to one last year to hear Geoff Young talk about mod_perl 2 (I think).

The big draw last night was a chance to meet David Wheeler. I worked with David on a nearly daily basis for over a year on the Bricolage project without ever meeting face-to-face. Aside from our running MySQL vs PostgreSQL "conversation," the meeting was a pleasant one. Things got a bit ugly when someone asked David for a "three sentence description of Krang" but I can't honestly say I would have handled a similar question about Bricolage with any greater sensitivity!

I also got a chance to talk to a couple guys working on Phalanxing HTML::Template. I'm looking forward to their contributions with a mixture of embarrassment and hopefullness. I'm sure better testing can only help, but that's some very old code and more than a little gross. Oh HTML::Template version 3, when will I write you?


Thursday February 24, 2005
03:53 PM

New versions of HTML::PopupTreeSelect and onchange

I released HTML::PopupTreeSelect v1.5 today (demo here). This release adds a 'resizable' option and fixes some HTML and CSS standards violations. Thanks to Zac Shepard, Peter Leonard and Don Brodale for all the new code!

I also updated my onchange script to do a recursive walk when passed a directory. I don't know if anyone else uses this script but I find it terribly useful.


Sunday February 13, 2005
08:07 PM

Narcissism, Thy Name is Homepage

I've updated my homepage. It's now mostly correct and contains pointers to nearly all my public work.

Now, for a second act, I think I'll go post my picture on Am I Hot or Not.


Wednesday February 09, 2005
01:33 PM

New Job

It's finally public where I work, so I can feel free to tell you all the good news. I've taken a job at Plus Three. I start next Tuesday.

I honestly couldn't be more excited about this for many reasons. To name just a few:

  • I'll be working for the good guys, rather than the usual money guys. Plus Three does work for non-profits and organizations like the Democratic National Committee and the United Federation of Teachers.
  • I'll be working on Krang again. Krang will likely play a big role in Plus Three's upcoming ARCOS product.
  • I'll be working with a good friend of mine, Perrin Harkins. We worked next to each other on different projects at Primedia for a short while and I think we're going to be a great team.
  • Everyone I've met at Plus Three seems happy to be there and excited about the work. That's a big change from my current job!
  • I'll be programming full-time, unlike my current 90/10 management/programming split which is making me into a bitter, unhappy man.