Chapter 9
Although the preceding code is specific to the needs of Gnome::MIME, it dem 
onstrates a general technique for XS modules that link to external libraries. You'll 
typically need to add some custom Perl code to your Makefile.PL to check that the 
library you need exists and has the right version. Then you'll need to figure out 
what to set LIBS and INC to so that your module will compile and link successfully. 
Sometimes this will be a static string, but it's becoming more and more common 
for large projects to provide a binary like gnome config that makes determining 
these variables easier.
A First XSUB
The fundamental unit of an XS module is an XSUB. An XSUB is simply a defi 
nition of a single C function for which the xsubpp compiler will produce a Perl 
subroutine. The first XSUB I'll provide for Gnome::MIME is a wrapper for the 
gnome_mime_type() function. This function takes a single parameter, a filename, 
and returns its MIME type based on an examination of the filename alone. The 
C signature for gnome_mime_type() is as follows:
const char * gnome_mime_type(const gchar *filename);
Here is an XSUB that provides an interface to this function:
char *
gnome_mime_type(filename)
     char *filename
See Listing 9 4 for the new MIME.xs.
Listing 9 4. MIME.xs with First XSUB Added
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Gnome::MIME   PACKAGE = Gnome::MIME
char *
gnome_mime_type(filename)
     char * filename
214






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

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