About once a quarter, MongoDB conducts a two-day Skunkworks session. Half-hackathon, half-incubator, the idea is to take a break from our day-to-day tasks and work feverishly for 48 hours on any project we want. Some projects are undertaken to scratch a particular itch and make our core products better. Others are for use inside the company to make our lives a little easier or more amusing. Still others are just for the hell of it. This quarter, my teammate Andrew Emil and I decided to work on something in the last category.

I recently started using Jeffrey Thalhammer's excellent Stratopan to manage CPAN dependencies for a new Perl project. I had played a little with Stratopan before, but now that I'm starting to get some use out of it, I am even more impressed with Jeffrey's work.

Stratopan allows you to create your own CPAN-like site in the cloud, which you can use to maintain a stable basket of dependencies for your project. You won't have to worry about new versions of distributions sneaking onto your private CPAN and breaking your stuff. Even better, you can upload your own, private CPAN-like distributions, and now you have the entire CPAN toolchain available to manage your internal codebase.

The one shortcoming I ran into was releasing my own distributions directly to Stratopan. Stratopan has a web interface where you can upload distribution tarballs, but I wanted to just be able to type dzil release, just like I do to make public CPAN releases. Those make use of Dist::Zilla::Plugin::UploadToCPAN, but there was no equivalent for Stratopan. Until now!

Removing Perl Boilerplate with Import::Into

| No Comments | 1 TrackBack

I recently started a new Perl project and wanted to take advantage of some cool new Perl 5.20 features. In particular, I wanted to use the experimental subroutine signatures feature and postfix dereferencing. That requires the following incantation:

use feature 'signatures';
use feature 'postderef';
no warnings 'experimental::signatures';
no warnings 'experimental::postderef';

That can be abbreviated a bit by passing a list to feature and just turning off the entire experimental class of warnings:

use feature 'signatures', 'postderef';
no warnings 'experimental';

But it's still a couple lines of boilerplate that need to be pasted atop every file in my project. I hate pasting things.

Arrays vs. Lists in Perl: What's the Difference?

| 3 Comments | No TrackBacks

One of the most common sources of confusion for new Perl programmers is the difference between arrays and lists. Although they sometimes look similar, they are very different things, and many bugs and misunderstandings are caused by not having a full understanding of the differences. Even experienced Perl programmers sometimes think arrays and lists are the same, but they are quite different in several important ways.

Here's a table which outlines some of the differences. Each of these differences is discussed in detail below.

...are variables....are ephemeral.
...can be changed....are immutable.
...can be named or anonymous....never have names.
...use the sigil @....do not have sigils.
...can be referenced....distribute references.
...can not be passed to or returned from subroutines....are the only thing passed to and returned from subroutines.
...can be multidimensional....are always one-dimensional.
...have known behavior in scalar context....do not exist in scalar context.

MongoDB Driver 0.502 Released

| No Comments | No TrackBacks

I'm happy to announce the release of the latest version of the Perl MongoDB driver. This version has a number of significant changes, including the new MongoClient top-level API. This change unifies the API nomenclature among most of MongoDB's officially supported driver libraries. It is also now the default behavior for MongoDB drivers to issue a write concern of 1 on all requests.

I'll be speaking on October 24th at MongoDB Boston 2012, taking place at the lovely Marriot Courtyard Tremont/Downtown.

Conference registration is a mere $100 ($30 for students). There are three tracks, covering everything from beginner topics presented by 10gen staff to advanced, detailed MongoDB presentations by industry leaders. Here's the abstract for my talk:

This talk introduces the features of MongoDB by demonstrating how one can build a simple library application. The talk will cover the basics of MongoDB's document model, query language, and API. In addition, we will learn how to use MongoDB within a typical web application framework.

If you're in Boston and you've never used MongoDB before, or are thinking of trying it out, I'd highly recommend stopping by. The demo application for the talk is written with Mojolicious::Lite and will soon be available on GitHub for you to experiment with.

Structured Data and the Road to Obsolescence

| 1 Comment | No TrackBacks

Starting with MongoDB.pm 0.46.3, MongoDB is no longer supported on Perl 5.8 and below. (If you must use 5.8, you can still use old versions of the driver, but you won't get any cool new features.) The first release of Perl 5.8 turned ten years old in July, so the fact that more and more of CPAN lists Perl 5.10 (or even 5.12) as a dependency should come as no shock. The current release of Perl is 5.16.

One of my many rules of software engineering, born of more than a decade seeing things done the Wrong Way, is that serialization must occur only at the extreme edges of your program. At all other points you should, if possible, deal only with structured data. The lack of it in one crucial area of the Perl MongoDB driver is what made support for Perl 5.8 no longer possible.

Toward a Unified libbson

| No Comments | No TrackBacks

BSON (binary JSON) is the data serialization format that MongoDB uses internally and over the network. It's a simple and expressive format which is easy to parse and efficient to store. When BSON documents are retrieved from the MongoDB store, they must be deserialized by the client-side driver code and inflated into the native structures of the programming language being used. Unfortunately, this has resulted in a great deal of code duplication, as each language driver has implemented its own BSON encoder and decoder, sometimes on multiple occasions.

Fast datetimes in MongoDB

| No Comments | No TrackBacks

One of the most common complaints about the Perl MongoDB driver is that it tries to be a little too clever. In the current production release of MongoDB.pm (version 0.46.2 as of this writing), all datetime values retrieved by a query are automatically instantiated as DateTime objects.

DateTime is a remarkable CPAN distribution. In fact, I would say that DateTime and its related distributions on CPAN comprise one of the best date and time manipulation libraries in any programming language. But that power comes with a cost. The DateTime codebase is large, and instantiating DateTime objects is expensive. The constructor performs a great deal of validation, and creates a large amouunt of metadata which is stored inside the object.

Upcoming changes to the Perl MongoDB driver solve this problem.

MongoDB 0.46.1 Released

| No Comments | No TrackBacks

I'm happy to announce that after a long delay, version 0.46.1 of the Perl MongoDB driver has now been uploaded to CPAN, and should be available on your friendly local CPAN mirror soon.

This release is mostly a series of minor fixes and housekeeping, in preparation for developing a more detailed roadmap for more frequent releases down the line. Here's what's new so far: