Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Extending and Embedding Perl

by cmilfo (Hermit)
on Oct 15, 2002 at 06:12 UTC ( #205284=bookreview: print w/ replies, xml ) Need Help??

Order Extending and Embedding Perl

Item Description: From Manning, "Extending and Embedding Perl explains how to expand the functionality and usefulness of the Perl programming language and how to use Perl from C programs."

Review Synopsis: This book was indispensable in gaining a good foot-hold on using Perl in, from, and around C.

Extending and Embedding Perl
Tim Jenness, Simon Cozens

Review By Brandon Willis
Conway Perl Mongers

The Scoop:
      Enjoy using Perl? Ever marvel at how Perl can do the right thing but still be written in C? Extending and Embedding Perl aims to take the black magic out of understanding our favorite language. In fact, the authors flat out admit they think it is unfair that only über-hackers get to have one foot in Perl and one in C. Tim Jenness and Simon Cozens attempt to break down that barrier with lots of annotated code examples, direct analogies from the structures in Perl to those in C, a fine-grain look at XS and what it takes to robustly use a Perl interpreter in C.

What's that up your sleeve?
      It is my experience that many situations require us to thoroughly examine a solution to understand how to best use it effectively. Perl is no exception. The ability to bring such a force as Perl to a project at the proper time is a valuable skill to possess. However, wading chest deep into XS and the Perl internals is not for the faint of heart. Jenness and Cozens ease this process by stepping in lightly at first.

What's in it?
      The book begins with simple C examples that are then related back to the readers' knowledge of Perl. Then the text seems to throw us a curve by leaping off into building Perl modules. But there is method to the madness. Building Perl modules correctly is inextricably linked to XS. Light introductions to XS are performed and the reader is well on his/her way to building .so extensions to any .pm.

      After building a very specific foundation of simple C examples, module building, and some XS, the text returns to C to introduce pointers, arrays, file I/O and memory management. With these new skills we begin to explore the structure and implementation of Perl variable types. Chapter 4 provides many useful diagrams of how Perl variables appear and into which C structures they translate.

      Still following a logical and constant order, we explore the Perl 5 API, learning how to post and retrieve information to the variable types explored in the previous chapter. As much as it might seem, this is not a rehash of the perlapi doc. It is consistent with the perlapi doc, but Jenness and Cozens provide extensively annotated C code examples.

      Casting deeper still, we add the advanced C of pointers, arrays, file I/O and memory management to our knowledge of XS. At this point we have everything we need to effectively extend Perl, but the text continues deeper still by exploring how XSUB interfaces to Perl's internals. It is only the clearly documented, step by step explanations of this chapter that make it manageable for an average user like myself. Chapter 7 ends our stint with XS by discussing some alternative XS (or equivalent code) generation suites.

      Switching gears entirely, we grab libperl.a and stuff into a C program. Chapter 8 begins the task of embedding Perl into a C program. Jenness and Cozens continue the embedded discussion through a Case Study in Chapter 9 and end with a look through the Perl internals in Chapter 10.

      The final chapter (Chapter 11) details some of Perl's history, its development process, how we could become involved and what the future of Perl and Perl 6 may entail.

Final Thought
      This book was indispensable in gaining a good foot-hold on using Perl in, from, and around C. I found it a good reference guide as well as an easy linear read. It is not a replacement for the perlguts, perlapi and perlxs documentation. But then again, it doesn't try to be. The annotated code examples with every line explained make following the book with development of your own solution a lot easier than in some other books. However, the in-depth explanations can be a bit frustrating for the impatient.

Comment on Extending and Embedding Perl
Re: Extending and Embedding Perl
by diotalevi (Canon) on Oct 15, 2002 at 13:03 UTC

    Good review - on a related note there's a book on Inline::C in the works Inline the Book, We have a Wiki and (not yet relevant but still humorous) Death to XS.

    Anyone looking into external integration should look at Inline::* prior to going XS. Really. XS is worth knowing but it's not the best of destinations.

    __SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B:: +svref_2object(sub{})->OUTSIDE
Re: Extending and Embedding Perl
by spx2 (Chaplain) on Mar 02, 2010 at 03:39 UTC
    This book kicks ass! It gives you the feel it's been written to be read and not to be sold. It has good descriptions of the internal structures that Perl uses and it explains how the XS code is parsed and transformed to C code. The figures are drawn with care and the book abounds in examples and relevant explanations. It is a very good complement to perlxs , perlapi , perlxstut , illguts .

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: bookreview [id://205284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-02 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls