Embedding the Mono runtime in Perl

by Paolo Molaro, Johannes Roith

Contents

I. Introduction

This document describes how to embed the Mono runtime in your Perl application. You can also get Paolo Molars's sample Mono module for Perl.

Mono can be embedded in every language, that allow C extensions/plugins, or is written in C. Unlike a CIL Perl compiler, such Perl code doesn't have all the advantages, that C# or Mbas code has. It doesn't run with the .NET Runtime and is not necessarily portable. The application is not executes by mono, but with the Perl interpreter.

Because of that, this is especially used to use the powerful class library, GTK# or other C# classes of mono. For example with Paolos Perl binding, you don't need Gnome Perl bindings anymore. Perl can make use of GTK#. It can also access Databases through ADO.NET, make use of the XML classes, etc. It can't do ASP.NET for example, because it's not a cil application.

// Example Perl script, making use of 
// the mono class library.

// © Copyright 2002 by Paolo Molaro

use blib;
use Mono qw(System::Console System::Environment);

System::Console::WriteLine ("from perl");
System::Console::WriteLine (10);

$user = System::Environment::get_UserName ();

print "the current user is $user\n";

Embedding the runtime

Now let's see how it is done.