[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
[PATCH] XSLoader nits and tests
I've added some really basic tests for XSLoader as well as cleaning up
a few nits in the code.
User visable changes:
load() will now die with a usage message if it gets no args rather than
just puking its guts out.
Doc changes:
The SYNOPSIS documented the second argumen to load() as "@args". It seems
more useful to call it some variation on $VERSION.
Code changes:
There were a bunch of comments and code copied from DynaLoader which seemed
to be cargo-cult. Particularly, the Tolkien quote which I've removed.
A better quote would be something about making a quick meal. :)
Tests:
. XSLoader loads.
. XSLoader::load() exists
. load() dies gracefully with no args
. SDBM_File can be loaded (I picked SDBM_File because I think its always
built)
That last test of SDBM_File isn't entirely correct. Because there's no
.so in the directory with the test, XSLoader can't find it so it will always
fall back to DynaLoader. So its only testing a small portion of XSLoader.
Still, its better than nothing.
The test might need some sort of "am I using dynamic loading" check.
--
Michael G Schwern schwern@pobox.com http://www.pobox.com/~schwern/
You'll do.
--- ./ext/DynaLoader/XSLoader_pm.PL 2003/08/30 05:44:23 1.1
+++ ./ext/DynaLoader/XSLoader_pm.PL 2003/08/30 05:45:12
@@ -14,19 +14,7 @@
package XSLoader;
-# And Gandalf said: 'Many folk like to know beforehand what is to
-# be set on the table; but those who have laboured to prepare the
-# feast like to keep their secret; for wonder makes the words of
-# praise louder.'
-
-# (Quote from Tolkien sugested by Anno Siegel.)
-#
-# See pod text at end of file for documentation.
-# See also ext/DynaLoader/README in source tree for other information.
-#
-# Tim.Bunce@ig.co.uk, August 1994
-
-$VERSION = "0.01"; # avoid typo warning
+$VERSION = "0.02";
# enable debug/trace messages from DynaLoader perl code
# $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
@@ -45,14 +33,11 @@
!defined(&dl_error);
package XSLoader;
-1; # End of main code
-
-# The bootstrap function cannot be autoloaded (without complications)
-# so we define it here:
-
sub load {
package DynaLoader;
+ die q{XSLoader::load('Your::Module', $Your::Module::VERSION)} unless @_;
+
my($module) = $_[0];
# work with static linking too
@@ -137,6 +122,8 @@
goto &DynaLoader::bootstrap_inherit;
}
+1;
+
__END__
=head1 NAME
@@ -148,7 +135,7 @@
package YourPackage;
use XSLoader;
- XSLoader::load 'YourPackage', @args;
+ XSLoader::load 'YourPackage', $YourPackage::VERSION;
=head1 DESCRIPTION
--- ./MANIFEST 2003/08/30 05:48:04 1.1
+++ ./MANIFEST 2003/08/30 05:48:20
@@ -214,6 +214,7 @@
ext/DynaLoader/hints/openbsd.pl Hint for DynaLoader for named architecture
ext/DynaLoader/Makefile.PL Dynamic Loader makefile writer
ext/DynaLoader/README Dynamic Loader notes and intro
+ext/DynaLoader/t/XSLoader.t See if XSLoader works
ext/DynaLoader/XSLoader_pm.PL Simple XS Loader perl module
ext/Encode/AUTHORS List of authors
ext/Encode/bin/enc2xs Encode module generator
--- /dev/null 2003-08-29 22:48:05.000000000 -0700
+++ ext/DynaLoader/t/XSLoader.t 2003-08-29 22:46:42.000000000 -0700
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+ chdir 't';
+# @INC = '../lib';
+}
+
+use Test;
+plan tests => 4;
+
+use XSLoader;
+ok(1);
+ok( ref XSLoader->can('load') );
+
+eval { XSLoader::load(); };
+ok( $@ =~ /^XSLoader::load\('Your::Module', \$Your::Module::VERSION\)/ );
+
+package SDBM_File;
+XSLoader::load('SDBM_File');
+::ok( ref SDBM_File->can('TIEHASH') );
- Follow-Ups from:
-
Rafael Garcia-Suarez <rgarciasuarez@free.fr>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]