LanguagesPerlThe PerlNET Project

The PerlNET Project

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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:

# Use pragma to ensure .NET calls
use PerlNET qw (AUTOCALL);

# Call new constructor
my $object = Namespace::Object->new();

# Call method 1 of object
$object->method1();

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.

References/Resources

Microsoft’s Project 7:

http://research.microsoft.com/project7.net/project_7.htm

The .NET SDK:

http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml

The Common Type System Overview

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcommontypesystemoverview.asp

Common Language Specification

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconwhatiscommonlanguagespecification.asp

Perl for .NET research

http://www.activestate.com/Corporate/Initiatives/NET/Research.html?_x=1

PerlNET

http://aspn.activestate.com/ASPN/Downloads/PerlNET/More

ActiveState’s Perl Development Kit

http://www.activestate.com/Products/Perl_Dev_Kit/

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories