Ingy 2.ö

Monday, March 10, 2008

Comprehensive Programming Archive Network

Tonight I uploaded jQuery to CPAN.

True. The 'j' in that sentence stands for JavaScript, and the 'P' stands for Perl. So why put a top notch JavaScript library on the world renowned archive network traditionally used for Perl?

To me it's all just about programming. I have been a major Perl module author since 2000AD. Last time I checked, less than 10 people have more Perl modules on CPAN. For the last 3 years I have been hacking more JavaScript than Perl. I do this mostly for work, but since my work supports Open Source, I have released much of this code as JavaScript modules on JSAN. I happen to be the only person in the world with a module that is both on JSAN and CPAN; the Jemplate module, because it is half Perl and half JavaScript. (It lets Perl's famous Template Toolkit be used in JavaScript).

JSAN was a really good idea, and led to some key people porting important parts of the Perl packaging framework to JavaScript. Especially the test framework. The result is that there is a fairly standard way to package JavaScript modules, especially if you are a CPAN guy like me.

The problem is that there are only a very small handful of folks paying any attention to the upkeep of JSAN. Truthfully JSAN will never be close to what CPAN is. Fortunately, I have found out it really doesn't need to be. :)

I started toying with the idea of putting other languages on CPAN about 5 years ago, but decided against it after discussing it with some Perl mongers at OSCON. I also started in 2003 with the goal of making a CPAN for all languages, but that project never really took off.

A couple weeks ago I started rethinking the whole thing. Certainly most languages have their own strong communities and distribution systems in 2008. But JavaScript (as a language) really doesn't. And almost every project I work on these days involves both Perl and JavaScript. And JSAN made JavaScript modules look like Perl modules. So I decided to look into how hard it would be to leverage CPAN for JavaScript's benefit. It was surprisingly easy.

It turns out that if you put any file in the lib/ directory of a CPAN module it will get installed. So, for example, lib/jQuery.js would be installed when the user runs make install.

However, I decided that it wouldn't be too cool to put the jQuery package on CPAN and let the user figure out that it was JavaScript and not Perl. Besides, there is already a Perl module called jQuery! I decided to put all these modules in the JS namespace. So jQuery becomes JS-jQuery on CPAN.

But what use is it to get JavaScript modules installed on your machine if JavaScript can't find them? I wrote a companion module called This module lets you run a command like:

> js-cpan jQuery.js /Library/Perl/5.8.8/JS/jQuery.js

So you can get the path names of the JavaScript modules you have on your system. You can then copy or symlink these modules into your web app. With a *nix command like this for example:

ln -s `js-cpan jQuery.js` jquery.js
Now you can distribute Perl web apps on CPAN that require certain JavaScript modules, and have them be included in the standard way as Perl module prerequisites.

For the most part, I plan to just upload my own JavaScript code to CPAN. But lately, almost everything I write in JavaScript relies on jQuery. It's just that good. If JavaScript 2.0 ever comes out, it should have the jQuery core included in the spec. :)


  • Hi ingy.

    I like this idea. The CPAN is a comfy place for software... and I'm comfortable using it. Putting non-Perl stuff on the CPAN makes it easy to use non-Perl stuff, which is always good.

    Especially in the case of javascript; it can take a lot of effort to find a module you like, get its dependencies together, and put them in your application's distribution. Saying "require 'js-FooBar'" in my Makefile.PL is much easier.

    By Blogger jrockway, At March 11, 2008 2:25 PM  

  • Ingy++

    I like it.

    By Blogger Luke, At March 11, 2008 4:45 PM  

  • Why aint you racing your bike? Are you fat? Are you funny looking? Honestly, we miss your colorful personality and ability to eat pocketfulls of hotdogs during difficult training rides.

    By Blogger Honey, At March 29, 2008 9:08 PM  

Post a Comment

<< Home