The PerlNET Project

Microsoft's own Project 7 has been pushing to get languages running within .NET's Common Language Runtime, and heads the front for Pascal, Scheme, Oberon, Mercury, and SML. ActiveState has jumped on board with a recent addition to their development kit: PerlNET.

The PerlNET project is ActiveState's project for integrating Perl into .NET, and into .NET's Common Type System and Common Language Runtime. The Common Type System is the system that every language porting into .NET needs to conform to. The specification allows for a handful of types: integers (int, int32, and int64), floating numbers, references, two types of pointers (managed, which are trusted; and unmanaged, which are not trusted), structures, and enumerations.

A subset of the Common Type System is the Common Language Specification, which is the common set of language features that enable an application to communicate with all other CLR languages. Along with the Common Language Runtime, the CLS specifies which operations are allowed, such as exception handling, branch operations, and the loading and storing of constants, variables, arguments, and arrays.

ActiveState started work on integrating Perl into .NET with Perl for .NET research. Perl for .NET research was a research project creating a native .NET code compiler for Perl. This project supported a subset of Perl within the .NET framework, and was compatible with the Visual Studio .NET Beta and Perl 5.6.0.

Perl for .NET research led to the PerlNET project, and the addition of .NET integration into ActiveState's Perl Development kit. PerlNET allows .NET Framework code to access Perl code running outside of the .NET framework using the Perl interpreter. The kit supports all of Perl's extension modules and ActiveState claims that the Perl run speeds are the same inside and outside of .NET.

The code itself is compatible with standard Perl. You can create new .NET components and extend existing .NET components, all written within Perl. .NET can also call into Perl, and Perl can make calls into the .NET framework library. You can also wrap Perl modules into .NET, so if you absolutely needed to have the latest math modules from CPAN, they can be wrapped up as .NET components. All this is made possible through the work of DLLs, which is what PerlNET uses to communicate with .NET.

As an example, let's say you wanted to access the function ReadLine within Console, which is within the System namespace. In .NET, the code to access ReadLine in would look like:

using System;
Console.ReadLine();

With PerlNET, the same .NET function is available using the familiar Perl commands for accessing methods:

use namespace "System";
Console->ReadLine();

Perl's syntax for instantiating objects and calling their methods can be translated into .NET calls by utilizing a PerlNET pragma:

PerlNET is part of ActiveState's Perl Development Kit, and is likely the first of many ports into the .NET Common Language. For the Windows user, the dev kit also comes packaged with tools allows that enable Perl developers to create standalone ActiveX components, windows services, and windows applications—all within the familiar Perl code base.