Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Make Your Existing Perl Apps .NET-compliant  : Page 4

Learn how CPAN Perl modules can be made automatically available to the .NET framework. The technique involves providing small PerlNET mediators between Perl and .NET and knowing when, where, and how to modify.


advertisement
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!



Yevgeny Menaker is a developer, author, and Linux consultant with more than 5 years of experience. For the past three years, Yevgeny has been focused on developing new and advanced Internet technologies and Internet/COM/ATL applications. He is currently working on migrating to .NET technology. He is the lead author of "Programming Perl in the .NET Environment" (Prentice-Hall). Additionally, he worked with Object Innovations as a Linux consultant. He can be reached at jeka_books@hotmail.com.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap