Writing C Modules with XS
MIME.pm The Module File
The module file generated for an XS module is mostly the same as that for a
Perl only module with a few additions. First, a new require is specified:
require DynaLoader;
This line pulls in the DynaLoader module that allows Perl modules to load shared
libraries. Next, DynaLoader is added to the @ISA inheritance array:
our @ISA = qw(Exporter DynaLoader);
Inheriting from DynaLoader is the standard way to allow your module to be
partially implemented in XS. Later in the file, the bootstrap() subroutine from
DynaLoader is called:
bootstrap Gnome::MIME $VERSION;
This call to DynaLoader::bootstrap() finds and loads a shared library corresponding to
Gnome::MIME. By passing $VERSION as the second argument, DynaLoader will
check that the loaded shared library matches this version of the Perl half of the
module. This is not a required parameter, but h2xs defaults to including it since it
helps prevent a very common class of errors.
Listing 9 1 shows a module file generated for an XS module.
Listing 9 1. MIME.pm Generated by h2xs A n Gnome::MIME
package Gnome::MIME;
use 5.006;
use strict;
use warnings;
require Exporter;
require DynaLoader;
our @ISA = qw(Exporter DynaLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
20
207
7
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