|The stupid question is the question not asked|
Extending and Embedding Perlby marvell (Pilgrim)
|on Nov 12, 2002 at 10:35 UTC||Need Help??|
Item Description: The definitive guide to XS, embedding and the Perl internals
Review Synopsis: It does exactly what it says on the tin.
My expectations before reading this book were that it was going to be hard work. The topic of the book is not one for the weak hearted and previous literature and tutorials were either limited or too terse to actually get a good grip on the subject in any depth. In short, this stuff is, or I should now say "was", 'a dark art'.
I assumed the book would assume you knew both Perl and C. As an accomplished Perl and C programmer, I presumed that I'd meet these requirements, so I donned my black pointy hat and headed for wizard school.
I was pleasantly surprised to find an introduction to C in the first chapter. I must admit, I did skim read it. It was entitled "C for Perl programmers" which seemed a bit of an odd angle, but was done very well.
Chapter 2 was a pleasure, giving a complete overhaul of the process of creating and building Perl modules for distribution. With excellent references and examples, the beginning of this chapter explains the components of a modules distribution with all its files and methods for producing them. This would be very useful for those using pure Perl create modules.
This chapter continued with a few bits of information about how XS, C and Perl talk to each other, with superbly annotated examples. By this stage, you could write basic interfaces to C programs using XS and make a complete distributed module suitable for CPAN.
The following chapter delves further into C. It talks about arrays, pointers, strings, structures and other Cisms. It also broaches memory management, which I'm sure most Perl programmers have been happy to have not needed in the past. With another array (no pun intended) of examples, each well annotated, the authors lead you along the learning curve with ease. There's even a reference to cdecl, which was a refreshing blast from the past.
Having read the rest of the book, I'm not sure that you're average C newbie would have been able to grasp all the concepts with the two C chapters. It's not an easy language and it's not good to try and transition from Perl. Of course, the book is not supposed to be a C book, and you're not going to learn C from it. With a good C book to hand, and some experimentation, I'm sure most good Perl programmers could pick it up.
Chapter 4 discusses the Perl variable types. I knew nothing about this before reading it, other than some imagined structures with reference counters. I was amazed how quickly it all began to sink in. The authors' style, together with the constant stream of examples, really helped the information hit the right spot. Devel::Peak was new on me and a very useful tool indeed. Chapter 5 goes into the Perl API. Quite a brisk introduction, but again, the style and examples made it easy reading.
The following chapter got on to more advanced XS programming. Drawing on new found knowledge from the earlier chapters with good references, we're now getting into the good stuff. Packed with tips and comparisons of different methods, this is one of the most important chapters to read right through. It brings in PDL too, which has some important efficiency and data management issues associated with it. This chapter is also where you'll find out about interfacing to other languages, like Fortran and C++. It's quote a long and heavy going chapter, and you'll need to refer back a lot, but it's all there.
If the book had stopped at this point, it would have provided an extensive insight into extending Perl. I would have been a very good book indeed. However, it just keeps going with more and more info.
Chapter 7 gives an insight into the alternatives to XS, including a very good look at Inline. Again, great annotated example and plenty of info about how to use the modules in the best way.
At this stage, the reader has all to tool, techniques and reference required to embed C in Perl. Chapter 8, now begins the process of teaching us how to to embed Perl in C. After a another good set of examples, Chapter 9 is a well documented case study of embedding Perl in C.
Chapters 10 and 11, discuss the Perl internals and how to hack around with Perl. There are plenty of tips and useful development modules references as well as an insight into development tracks and versioning system. This is also where you find more information about debugging at various levels.
In summary, I've not seen a more complete and well written source of information on the subject of embedding. The book is much more than an introduction, it covers many subjects and gets quite heavy. Each chapter has a extensive set of annotated examples and the style of writing makes the learning process easier. The book is full of internal references and each chapter has a good list of external reading material. The book is great for learning and great for reference, which is a combination other books often fail to achieve.
Steve Marvell is the Proprietor of an IT Solutions Provider based in the South West of England and runs the Devon and Cornwall Perl Mongers.
This review may be used, in full, including this message, by anyone, but may not be edited without the author's permission.