Many Perl subroutines accept a Perl array or hashe of dynamic length as an argument. In the interface definition of the wrapper class, you need to supply the fixed number of arguments. For instance, the Postscript::Simple module from CPAN provides a simple functionality for creating Postscript files. Its constructor accepts hash as an argument, through which you supply the initial properties, such as page size, for the new document. One simple way to deal with this is to define the following prototype for the constructor:
static Simple(str key1, str value1,
str key2, str value2,
str key3, str value3);
This method limits you to hashes with three values. Another method is to overload the constructor with additional versions:
static Simple(str key1, str value1);
static Simple(str key1, str value1,
str key2, str value2);
A more elegant solution is to define a special method that accepts the .NET array as an argument. This special method transfers its elements into the Perl list and forwards the call to the original constructor. As a result, client programs will have to use your special method to construct objects of the class (instead of the new operator).
The wrapper class for the Postscript::Simple module (Listing 4) demonstrates this technique. The SimpleCtor method translates the .NET array into the Perl list and calls the original constructor. Property method collisions are also handled because the wrapper exposes only part of methods provided by the module. The client program (Listing 5) illustrates how to use this class to create simple postscript documents from the C# code. Notice, that you call the SimpleCtor static method to instantiate the Postscript.Simple object.
One of the key features of PerlNET is the ability to wrap existing Perl components. There are many more to be explored. With PerlNET, you can create .NET native components, work with Windows Forms, access databases through ADO.NET classes, create ASP.NET Web Forms, and loads of other .NET-relative tasks. One thing is certain: Perl's new .NET compliance promises to strengthen the language's appeal to a wider audience of developers. It may be worth it to keep your eye on Perl!