Extending and Embedding Perl
It is my experience that many situations require us to "look under the hood" of (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 "look" and what C structures they translate into.
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 foothold 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.
You can purchase Extending and Embedding Perl from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
The day was one of the most hellacious in a long time. We were doing end of the year closing at the office and I'd been working 12-14 hour days tying up loose ends. I entered the subway station at 1:45 am and waited for the 2 am train. I ran my hands through my hair and exhaled a long breath, very thankful I wasn't working the next day. The train arrived and I entered a deserted car. Slouching in a corner seat, I prepared for the 40 minute ride home. At the next stop, I noticed an attractive Spanish woman entering my car. She was about 5'6" and had dark brown hair that framed her face and rested on her shoulders. My eyes traveled down her body, appreciating her pert breasts confined in a tight white blouse and her curvaceous hips hugged by a midnight blue skirt that stopped at her knees. She glanced my way long enough for me to notice her eyes were as dark as her hair. I studied her luscious ass as she walked to the other end of the car and sat down.
I was so tired my eyes began to drift closed. When I next opened them, I looked at my watch and checked that I hadn't missed my stop. My head shot up in surprise when I noticed the pretty stranger sitting across the aisle from me. She was studying me intently and I noticed the first few buttons of her blouse were undone and her hand was inside, obviously massaging her breast. Not missing my stop was no longer on my mind. I watched the mysterious beauty as she pushed the blouse from her shoulder, exposing her right breast to my hungry stare. She kept her eyes on me as my own watched her fingers tease her hardened nipple... rolling and pinching it. I heard a low moan escape her lips over the rumble of the subway train. I straightened in my seat, attempting to relieve the pull forming between my legs.
She pulled her legs into the seat and her skirt inched up, revealing nicely tanned thighs. It took all of my resolve not to move myself into her seat and slide my hand up her skin. The fact we were on a city train was still prevalent in my mind, however, did not seem to phase her in the least. She slipped a hand between her legs and I lost sight of it in the darkness beneath the material of her skirt; but the movement of her arm left no question of what she was doing. Her head rolled back and rested on the window, her eyes drifted closed as her hand worked its magic. I was lost in her movements, waiting for her body to shake with an orgasm... when she suddenly stopped and looked at me again. Biting her lower lip, she pulled her skirt up as far as it would go and brought her knees to her chest, spreading her legs and revealing her bare nether region to me.
I licked my suddenly dry lips as her hand drifted through the neatly trimmed pubic hair and down to her rosy brown labia... slowly spreading her pussy lips as if to show me how wet she was, and I watched her essence flow down the valley leading to her ass. I imagined my tongue darting hungrily into her cunt as she began to ferociously finger her swollen clit, her moans becoming louder. She began to thrust her hips up into her hand and I found myself rotating my own hips as well. Her body began to jerk and I moaned as she let out a small cry and a climax shot through her. Her breath coming in short rasps and her eyes dark with passion, she kept her gaze on me as she brought her hand to her mouth and sucked on her fingers, licking them clean. I grabbed the back of the seat and gripped hard.
The train pulled to a stop and I glanced up to see my station. I pulled myself slowly from my seat, noticing the liberal wetness that had formed between my legs. As I walked to the car door, I watched as the Latina beauty pulled her skirt down and her blouse back together. She smiled and winked at me as I stepped out onto the platform. I turned around and looked at her through the car window. She blew me a kiss and mouthed what looked like, "Until next time..." and the train disappeared down the track.
I headed up the station steps and wondered just when "next time" would be...