CHAPTER 9
Writing C Modules
with XS
N
OW 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://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.
205
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved