What Perl 5 and CPAN Built — A Language That Succeeded Too Well to Change
In 1994 the Perl interpreter was rewritten from scratch: references, modules, bless-based OO, lexical scoping. The following year CPAN appeared — something that existed in no other language at the time. And Perl 5 succeeded too well. The very fact that thirty years of modules keep working is what would later force the conclusion that breaking compatibility meant building a different language.
Last time I got as far as the two constraints Perl 4 carried: data structures that could not nest, and a namespace that was only ever global. And that the way out was not “improve it” but “rewrite from scratch.”
This time: that rewrite, and what happened the year after.
17 October 1994 — Perl 5.000
The interpreter was rewritten wholesale. Not new syntax but a reconstructed implementation, and this is where Perl became a different language.
Four things went in.
References
\ gives you a reference to a scalar, array, hash, or subroutine.
my $data = {
users => [
{ name => 'alice', tags => ['admin'] },
{ name => 'bob', tags => [] },
],
};
This could not be written in Perl 4. The ceiling came off the shapes of data you could express.
Packages and Modules
Namespaces via package, loading via use / require.
What this means is that you could now pull in other people’s code a file at a time. And that is precisely the precondition for CPAN, which is the second half of this instalment.
Object Orientation — bless
Perl 5’s OO was built out of parts that already existed.
- An object is a reference (usually to a hash) with a class name stuck on it by
bless - A class is a package
- A method is a subroutine in that package
- Inheritance is the
@ISAarray
package Point;
sub new {
my ($class, %args) = @_;
my $self = { x => $args{x} // 0, y => $args{y} // 0 };
return bless $self, $class;
}
sub to_string { my $self = shift; "($self->{x}, $self->{y})" }
Almost no new machinery was added. It is a proof that you can build OO from existing parts, and it is genuinely elegant.
It is also the basis of the later criticism that OO was never built into the language.
new is a convention, not a feature. There is no agreed way to declare attributes.
So schools of thought proliferated.
Perl 6 building class / has / method into the language is the answer to this.
Lexical Scoping — my
Lexical variables via my. Unlike local (dynamic scope), these close over a block.
Combined with use strict, this is what made Perl a language you could write large programs in.
26 October 1995 — CPAN
The Comprehensive Perl Archive Network. An archive network for collecting and distributing Perl modules.
It is probably the single most influential invention in Perl’s history. And the point worth stating plainly is that nothing equivalent existed in any language at the time.
| System | Started |
|---|---|
| CPAN | 1995 |
| PyPI | 2003 |
| RubyGems | 2004 |
| npm | 2010 |
| Cargo (crates.io) | 2014 |
For eight years, CPAN had nothing to be compared against.
What CPAN Invented
If it were only “a place to put modules,” FTP sites already existed. What made CPAN different is that it had the surrounding machinery from the start.
1. PAUSE — author registration and namespace management
Who may publish a module under which name. Name collisions solved by process, not technology.
2. Standardised metadata
Dependencies, licence, required Perl version — machine-readable, so an installer can resolve dependencies on its own.
3. A mirror network
Distributed mirrors worldwide. With 1995 connectivity, this was not a nicety.
4. CPAN Testers
This is the strangest one. A system that automatically runs a module’s tests across many platforms and many Perl versions, and publishes the results.
An author can see results from operating systems they do not own and versions they do not run. In the 1990s, they built institutional machinery for getting past “works on my machine.”
The equivalent of modern CI existed as a feature of the package repository. And here is the interesting part: later package managers did not inherit it. Neither npm nor RubyGems has an official equivalent.
Writing about CPAN usually means citing module counts. But the invention worth noting is not the number — it is that all four of these mechanisms were there from the beginning.
The Duct Tape of the Internet
In the late 1990s Perl became the main language of the web, for three reasons.
1. CGI. A protocol that works entirely through standard I/O and environment variables is ideal for a text-processing language.
2. String handling. HTTP and HTML are both text. Perl’s regular expressions were the weapon.
3. mod_perl (1996, Doug MacEachern). Embedding a Perl interpreter into Apache removed process startup cost. In practice, one of the first application servers.
Perl in this era was called “the duct tape of the Internet.” Amazon, early Slashdot, and countless other sites ran on it.
Perl 5.6 (March 2000)
Version numbering changed from the 5.005 form to 5.6.0. In substance:
- Initial Unicode support
ourfor declaring package variables- 64-bit support, large file handling
And four months later, Perl 6 was announced.
This gets misread often enough to be worth emphasising. Perl 6 did not begin because Perl was in decline. It was conceived when Perl dominated the web, when CPAN was an asset with no equal — at the peak.
A Language That Succeeded Too Well
This is the part of this instalment I most wanted to write.
Some of Perl 5’s design decisions became things people wanted to change and could not.
| Decision | What went wrong |
|---|---|
Sigils shift with context (@a’s element is $a[0]) |
The single biggest stumbling block for beginners |
| bless-based OO | No standard way to write it, so schools proliferated |
Arguments arrive in @_ |
You cannot write a signature |
| Context (scalar/list) is implicit | Behaviour is hard to predict |
None of these could be changed in Perl 5. Because of backward compatibility.
And backward compatibility weighed as much as it did precisely because CPAN existed.
- Tens of thousands of modules working
- Production systems worldwide working
- Thirty years of accumulated assets
Perl 5’s greatest asset was what made Perl 5 unchangeable.
There is a pattern here that recurs throughout this series.
A successful language gets fixed in the shape of its success. The larger the accumulated assets, the higher the cost of fundamental change.
At Perl 4, the assets were still small enough to rewrite, and compatibility was broadly kept. At Perl 5, that was no longer possible.
So the judgement in 2000 came out like this:
We want to change it fundamentally. But Perl 5 cannot be changed. Therefore we must build a different language.
That is the starting point of Perl 6. And the fact that they gave a different language the name “Perl 6” is what would, nineteen years later, become the reason to change the name.
From the next instalment, we go in through that door.
Next (part 3): In 2000, Perl 6 began. A mug smashed at a Perl 5 Porters meeting, the announcement in a State of the Onion talk, and what happens when you crowdsource a language design — the story of 361 RFCs.