Chapter 9: Writing C Modules with XS

Chapter 9 - Writing C Modules with XS
by?Sam Tregar?
Apress ? 2002
has companion web siteCompanion Web Site

NOW THAT YOU'RE A Perl API yellow belt, it's time to learn to write Perl modules in C. XS is the name for the toolkit used to create most of the existing C modules on CPAN. It consists of two pieces: the XS language for expressing interfaces and the xsubpp compiler that generates C code from XS.

A Real-World Example

This section will use a real-world module as an example—Gnome::MIME. Gnome::MIME will provide an interface to the Gnome system's MIME-handling routines. The Gnome system is a desktop and component system for UNIX-like operating systems produced by the Free Software Foundation.[1] You can find more information at the Gnome Web site: http://www.gnome.org.

CPAN already has a Perl module that provides a binding to some of Gnome, although not to the MIME functions at present; you can find the Gnome module, written by Kenneth Albanowski and Paolo Molaro, on CPAN.

The Gnome MIME functions come from the packages gnome-mime and gnome-mime-info. They provide functions to guess MIME types given a file and functions to retrieve information about a MIME type. A MIME type is a standardized system for describing the type of a file. Example MIME types that you might be familiar with are text/html, image/gif, and application/pdf. MIME types are used in many applications, from Web browsers to e-mail programs to operating systems. You can find more information on the MIME types in RFC 2046, which is available here (among many other locations): http://www.rfc-editor.org/rfc/rfc2046.txt.

This example module is, by nature, platform specific and will only work on UNIX systems with Gnome installed. However, the basic techniques demonstrated can be used to create cross-platform XS modules.

[1]See http://www.fsf.org.



Writing Perl Modules for CPAN
Writing Perl Modules for CPAN
ISBN: 159059018X
EAN: 2147483647
Year: 2002
Pages: 110
Authors: Sam Tregar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net