Stories
Slash Boxes
Comments
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 ]

Yanick (3196)

Yanick
  (email not shown publicly)
http://babyl.dyndns.org/techblog

Journal of Yanick (3196)

Tuesday July 15, 2008
09:13 PM

Bart on Git

Bart Trojanowki gave a Git presentation to the Ottawa Ruby Group earlier this month (I attended as a deep undercover Perl mole). The slides and the podcast are now available at http://excess.org/article/2008/07/ogre-git-tutorial.

Very good presentation, meant as an introduction to the beast, but containing enough little nudgets to have anyone learn something from it.

Thursday July 10, 2008
10:31 PM

Bring the blog back hooome

Just to say that my main blog is going to be here (although I'm probably going to echo my posts at use.perl.org for a while still).

I love the soapbox that use.perl.org provides but the site's blogging interface is, shall we say, a tad archaic and on the painful side. I can live with the html format of entries, but many times I've longed for something a little bit more code snippet-friendly. So, when Perlsphere appeared at the horizon, the temptation to repatriate my blog on my own server became just too great to ignore...

Of course, considering that it's a blog about Perl blabbering, using some PHP blog engine would have not felt quite right. So I decided to experiment with Angerwhale. It's a pretty nifty engine, but it has a few rough edges. In fact, I already began to hack and patch at it... expect some entries about it sometimes soon. :-)

Thursday June 19, 2008
08:50 PM

Test::Class + Test::Group

I've been playing with Test::Class lately and, I must say, it's a heck of a nice module. Only thing that I wish it had is the possibility to report each test as a single pass/failure, no matter the number of assertions done in the function. Just like Test::Group does.

Hmmm... But wait a second. Could it be possible to somehow stuff the caramel-like sweetness of Test::Group in the smooth chocolatey wrapping of Test::Class? Turns out that yes, it's perfectly possible! And even more, without even having to muck with the guts of either modules:

package Some::TestSuite;

use base qw/ Test::Class /;
use Test::Group;
use Test::More;

sub Test :ATTR(CODE,RAWDATA) {
   my ( $pkg, $funct, $code ) = @_;

   no warnings;  # black magic starts here

   my $func_name = *{$funct}{NAME};
   my $fullname = $pkg.'::'.$func_name;

   *{$funct} = sub {
       print "begin test [", scalar localtime, "]\n";
       Test::Group::test( $fullname => \&{$code} );
       print "end test [", scalar localtime, "]\n";
   };

   Test::Class::Test( @_ );
}

sub aTest : Test {
    ok 1, 'eins';
    ok 1, 'zwei';
    ok 1, 'drei';
}

sub otherTest : Test {
    ok 1, 'un';
    ok 0, 'deux';
    ok 1, 'trois';
}

Some::TestSuite->runtests;

Which gives

$ perl test.t
1..2
begin test [Thu Jun 19 22:17:16 2008]
ok 1 - Some::TestSuite::aTest
end test [Thu Jun 19 22:17:16 2008]
begin test [Thu Jun 19 22:17:16 2008]
#   Failed test 'deux'
#   in a.t at line 32.
not ok 2 - Some::TestSuite::otherTest
#   Failed test 'Some::TestSuite::otherTest'
#   at a.t line 17.
#   (in Some::TestSuite->otherTest)
end test [Thu Jun 19 22:17:16 2008]
# Looks like you failed 1 test of 2.

This method, though, has two modest caveats:

  1. A failed assertion will be given with the correct line, but the test itself will be reported as being located inside the Test() function.
  2. Test fixtures have to be declared as having 1 test (i.e., it has to be sub mySetup :Test(setup => 1) { .. })
Sunday May 11, 2008
11:03 AM

Why I am passionate about Perl

The person who introduced me to Perl showed me that ... well, in my case it's kinda of a spurious question, considering that no-one really properly introduced me to the language. At the time, I just happened to look around for a good scripting language to learn and saw that Perl was one of the languages used by some members of my team. I bought the Camel book, dived in and... the rest is pretty much history.

I first starting using Perl to do small shell stuff. If I recall correctly, the first script I touched was a load balancer that was monitoring a unix corral and launching queued jobs on the less busy machines. Then I began to use it to diddle text files (change 'class Foo' to 'class Bar' in my source code, figure out how many functions are in each file, etc.). And then came the Solitaire 500. My entry to the contest shamefully crashed and burn at the starting line, but I still managed to squeeze a t-shirt and a love of the language out of the experience. To this day, I still have both (although one is pretty much due for replacement).

I kept using Perl because it is so much damn fun. Most other languages are like station wagon cars. They get you from A to B, but they are not much to write home about. But Perl... Perl is like James Bond's car. Beside the driving wheel, you have a red button here to activate the flamethrowers. Below the glove compartment -- yes, you see right -- there's a lever that engages the retro-propellers. And it doesn't end there: if one was to ever get bored with all those nifty toys, Q still comes up regularly with new features.

I can't stop thinking about Perl for the same reason a rock star can't stop thinking about his Fender Stratocaster XII.

I'm still using Perl because I have yet to find another language that is so delightfully idiosyncratic and yet so practical. Or that has such a striving community. Or that has anything remotely comparable to that magnificent temple dedicated to Aergia that we call CPAN.

I get other people to use Perl by asking them what task they want to achieve, and doing it before their eyes in a handful of lines. Once I have thus acquired their awestruck attention, I reel them in for my weekly Perl Lunch'n'Learns where the true corruption can begin.

I also program in TCL and Javascript, but I like Perl better since it doesn't make me want to drive red-hot tetanus-laden nails through my prosencephalon. Javascript is not that bad, mind you -- I actually like it. But nothing, nothing, can shear such deep gouges in one's psyche like badly written TCL can. And this is coming from someone who known Intercal, brainf*ck and VisualBasic...

Wednesday April 23, 2008
06:50 PM

CPAN/Ohloh mashup

Now that I've registered my Perl modules on Ohloh, I thought it'd be fun to make things bilateral and have one of the Ohloh widgets displayed on the modules' CPAN page. So I mustered my Grease-Fu, and hacked a little something.

With that little script installed, if a module dist is registered on Ohloh [*], its widget will appear on the right side of the CPAN page right below the gravatar picture.

For sample modules, have a gander at Test::Pod::Snippet or XML::XPathScript.

[*] The project must also be configured to have a name url corresponding to module's name in lowercase and with all '::' substitued by '-' (e.g., 'Test::Pod::Snippets' => 'test-pod-snippets').

Wednesday March 19, 2008
09:13 PM

per(l)version

Updating the version number is all the files of a module distribution is a pain in the behind. It's repetitive, boring and ridiculously prone to errors -- in short, a task fit for a script, not for humans. So I decided to hack myself a little something, for the time being called perversion, to take care of it.

The idea is pretty straight-forward. In the root directory of my distribution, I have a config file named perversionrc that contains Perl code that return an hash of all files where the the module version is given, and regular expressions to capture the said version. For example, here's the perversionrc of WWW::Ohloh::API:

use File::Find::Rule;

my %file;

$file{README} = qr/WWW-Ohloh-API version (\S+)/;

for my $m ( File::Find::Rule->file->name( '*.pm' )->in( 'lib' ) ) {
   $file{$m} = [ qr/\$VERSION\s*=\s*'(.*?)';/,
                 qr/This document describes \S+ version (\S*)/ ];
}

%file;

Once that file is present, perversion is ready to rock. You want to verify that the version number is consistent in all given files?

$ perversion
distribution version is set to 0.0.9
lib/WWW/Ohloh/API/Enlistment.pm:12: 0.0.6
!!! does not match distribution version (0.0.9) !!!
lib/WWW/Ohloh/API/Repository.pm:10: 0.0.6
!!! does not match distribution version (0.0.9) !!!
lib/WWW/Ohloh/API/ContributorLanguageFact.pm:10: 0.0.6
!!! does not match distribution version (0.0.9) !!!
lib/WWW/Ohloh/API/ContributorFact.pm:10: 0.0.6
!!! does not match distribution version (0.0.9) !!!
lib/WWW/Ohloh/API/ContributorFact.pm:241: 0.0.6
!!! does not match distribution version (0.0.9) !!!

Want to set the version to a specific value?

$ perversion -set 1.2.3
changing all versions to 1.2.3..
        updating lib/WWW/Ohloh/API.pm..
        updating lib/WWW/Ohloh/API/Language.pm..
        updating lib/WWW/Ohloh/API/ActivityFacts.pm..
        updating lib/WWW/Ohloh/API/Account.pm..
        updating lib/WWW/Ohloh/API/Kudos.pm..
        updating lib/WWW/Ohloh/API/Project.pm..
        updating lib/WWW/Ohloh/API/Enlistment.pm..
        updating lib/WWW/Ohloh/API/KudoScore.pm..
        updating lib/WWW/Ohloh/API/Factoid.pm..
        updating lib/WWW/Ohloh/API/Repository.pm..
        updating lib/WWW/Ohloh/API/Projects.pm..
        updating lib/WWW/Ohloh/API/ContributorLanguageFact.pm..
        updating lib/WWW/Ohloh/API/Languages.pm..
        updating lib/WWW/Ohloh/API/ActivityFact.pm..
        updating lib/WWW/Ohloh/API/ContributorFact.pm..
        updating lib/WWW/Ohloh/API/Analysis.pm..
        updating lib/WWW/Ohloh/API/Kudo.pm..
        updating README..
done

Don't want to go through the mental challenge of computing the next version yourself? No problem!

$ perversion -inc revision
distribution version is set to 1.2.3
new distribution version is 1.2.4

$ perversion -inc minor
distribution version is set to 1.2.4
new distribution version is 1.3.0

$ perversion -inc major
distribution version is set to 1.3.0
new distribution version is 2.0.0

$ perversion -inc alpha
distribution version is set to 2.0.0
new distribution version is 2.0_1

The script is still raw and in need of polishing, but for those interested, it's available from its very own git repository.

Saturday March 01, 2008
10:43 PM

XPathScript slides

An introduction to XPathScript that I gave at this month's Ottawa Mongers Meeting can be found here.

It probably reads a wee bit cryptic without my running commentaries, but some might still enjoy it. :-)

Tuesday February 12, 2008
12:24 PM

Thinking about taking over NetPacket

At $work, an application that I wrote (remora, a companion application to Wireshark) is extensively using NetPacket. NetPacket is very handy but, alas, has some bugs, and seem to be orphaned (the latest update is from 2003). I've tried to poke the maintainers, but Stephanie Wehner's email is no longer working, and Tim Potter didn't reply yet (although, to be fair, I only began to poke last week).

Bottom line, I'm playing with the idea of taking over the module so that I can churn a new version with the bug fixes. So if anyone out there is in contact with Stephanie or Tim, can you let them know a madman is nefariously organizing a coup? Thanks. :-)

Saturday February 09, 2008
05:18 PM

Git's the nightclub, Perltidy's the bouncer

I finally wrapped my CVS-encrusted mind around Git's hooks. Huzzah! The biggest hurdle, really, was realizing that there is no spoon.

Anyway, as I'm an unsalvageable slob who always forget to run perltidy before committing changes, I've written a pre-commit hook that makes sure that all Perl files to be committed are all clean, neat and tidy (and aborts the commit and chides me if they are not):

#!/usr/bin/perl

use Perl6::Slurp;

my $status = slurp '-|', 'git-status';

# only want what is going to be commited
$status =~ s/Changed but not updated.*$//s;

my @dirty =
  grep { !file_is_tidy($_) }                   # not tidy
  grep { /\.(pl|pod|pm|t)$/ }                  # perl file
  map  { /(?:modified|new file):\s+(\S+)/ }    # to be commited
  split "\n", $status;

exit 0 unless @dirty;                          # Alles gut

warn "following files are not tidy, aborting commit\n",
     map "\t$_\n" => @dirty;

exit 1;

### utility functions ###############################################

sub file_is_tidy {
    my $file = shift;

    my $original = slurp $file;
    my $tidied = slurp '-|', 'perltidy', $file, '-st';

    return $original eq $tidied;
}

Monday January 28, 2008
08:28 PM

Greasemonkeying dependencies

Escalation wars... you just have to love'em.

First, David came up with the über-cool CPAN deps page.

Then Andy comes up with a nifty Greasemonkey script to add it to the CPAN distributions main pages.

Then I add a small patch to the script to retrieve some information from the Deps page.

Then David creates an xml interface to CPAN deps, opening the door wide open for Web 2.0 goodiness.

Then (and this is where we are right now) I hack together a new CPAN_Dependencies monkeyscript to take advantage of said xml interface.

This, of course, is nowhere near the end of the story. My new script only scratches the surface of what can be done with the information contained in the xml. As soon as I have some tuits, I'll probably add a way to toggle between showing only the first-level dependencies and all dependencies, and have dependencies color-coded by degree of b0rkage, and whatever bell or whistle I can think of in the meantime.