Section B.24. Embedding

B.24. Embedding

The reverse of dynamic loading (in a sense) is embedding.

Suppose you want to make a cool word processor, and you start writing it in (say) C++.[] You decide you want the users to be able to use Perls regular expressions for an extra-powerful search-and-replace feature, so you embed Perl into your program. Then you realize you could open up some of the Perl's power to your users. A power user could write a subroutine in Perl that could become a menu item in your program. Users can customize the operation of your word processor by writing a little Perl. So, you open up a little space on your website where users can share and exchange these Perl snippets, and you've got thousands of new programmers extending what your program can do at no extra cost to your company. And how much do you have to pay Larry for all this? Nothing. Check the licenses that come with Perl. Larry is a nice guy. You should send him a thank-you note.

[] Thats probably the language we'd use for writing a word processor. Hey, we love Perl, but we didn't swear an oath in blood to use no other language. When language X is the best choice, use language X. But often, X equals Perl.

Though we don't know of such a word processor, some folks have used this technique to make other powerful programs. One such example is Apache's mod_perl, which embeds Perl into a powerful web server. If you're thinking about embedding Perl, you should check out mod_perl; since it's all open source, you can see how it works.

Learning Perl
Learning Perl, 5th Edition
ISBN: 0596520107
EAN: 2147483647
Year: 2003
Pages: 232

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: