Introduction to Perl on Windows: Writing COM Components in Perl
March 20, 2000
|
When you strip away all the layers of marketing hype and industry
jargon, Microsoft's Component Object Model (COM) is simply a
technology that allows you to create an object in the language of
your choice, and to make the functionality of that object available
to any other object, or any other application, regardless of the
language that the other object or application is written in.
|
Yikes! Quite a mouthful. Maybe it would be useful to come at this
by way of an example.
Suppose that we are required to write three applications. These
three applications will be identical in terms of functionality.
Specifically, they will gather data entered on a form and email it.
However, though all three applications will do the same thing, in
our hypothetical example, each application will be programmed in
a different programming
language.
Specifically, we will write one
form processor in C++, one in
Java, and one in
Perl.
In writing these applications, it is likely that we will define
several objects.
For example, there will be an object representing the form and
there will be an object in charge of connecting to a mail server
and delivering the email message.
In order for each program to work, each of these objects,
will have to be defined in each of the three languages. Thus, you
will have one mailer in C++, one mailer in Java, and one mailer in
Perl.
As you might imagine, this is quite inefficient. The algorithm
involved in connecting to a mail server and delivering the email
message is not really language specific. So why should we have to
write it three times?
Well traditionally, the reason is because C++ applications can't
really speak to Java objects. Java objects can't speak to Perl
objects and Perl objects can't speak to Visual Basic objects.
Traditionally, objects are like cliques in high school! Groups
never mingle.
In the COM universe however, anything can talk to anything else.
Thus, in the COM universe, you do not write three mailer objects.
Instead, you write one special mailer object that can be used by
any application in any language. It is an object that conforms to
the COM specification. It is a COM object.
As we said, this COM object may be written in any language you
like (C++, Java, Perl, VB, etc.) but because it conforms to the
COM specification, it will be available as a resource to any
COM-aware applications regardless of what language that application
is written in. Thus, you could write a single mailer (as a COM
object) in Perl and make that mailer available to all your programs,
whether those programs are written in Perl, Java, VB, or C++.
Contents:
What are COM objects?
The IDL
Multiple Interfaces
How does the IDL describe my object?
How do I package my PERL code as a COM component?
The Perl code for the object
Introduction to Perl on Windows - Table of Contents
What are COM objects?
|