diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-10-14 21:30:16 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-10-14 21:45:59 +0100 |
commit | 1d2b7ec55763d41a18a61d1b44aedd531d305ad3 (patch) | |
tree | f7dd4ef3013cf02265dbde82a97e71ad4044655b /dist/XSLoader/XSLoader_pm.PL | |
parent | 4f65bc30ea83f40e28f0ea56d45f48f300db8fcc (diff) | |
download | perl-1d2b7ec55763d41a18a61d1b44aedd531d305ad3.tar.gz |
XSLoader::load() with no arguments can use caller to find a default package.
In the case of dynamic linking, it's already using caller to get a filename, so
this isn't usually any extra work.
Diffstat (limited to 'dist/XSLoader/XSLoader_pm.PL')
-rw-r--r-- | dist/XSLoader/XSLoader_pm.PL | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/dist/XSLoader/XSLoader_pm.PL b/dist/XSLoader/XSLoader_pm.PL index 66afa8e6e0..0738fa5ed2 100644 --- a/dist/XSLoader/XSLoader_pm.PL +++ b/dist/XSLoader/XSLoader_pm.PL @@ -8,7 +8,7 @@ print OUT <<'EOT'; package XSLoader; -$VERSION = "0.12"; +$VERSION = "0.13"; #use strict; @@ -26,9 +26,13 @@ package XSLoader; sub load { package DynaLoader; - die q{XSLoader::load('Your::Module', $Your::Module::VERSION)} unless @_; + my ($module, $modlibname) = caller(); - my($module) = $_[0]; + if (@_) { + $module = $_[0]; + } else { + $_[0] = $module; + } # work with static linking too my $boots = "$module\::bootstrap"; @@ -58,7 +62,6 @@ EOT print OUT <<'EOT'; my $modpname = join('/',@modparts); - my $modlibname = (caller())[1]; my $c = @modparts; $modlibname =~ s,[\\/][^\\/]+$,, while $c--; # Q&D basename EOT @@ -178,14 +181,14 @@ XSLoader - Dynamically load C libraries into Perl code =head1 VERSION -Version 0.10 +Version 0.13 =head1 SYNOPSIS package YourPackage; - use XSLoader; + require XSLoader; - XSLoader::load 'YourPackage', $YourPackage::VERSION; + XSLoader::load(); =head1 DESCRIPTION @@ -234,6 +237,13 @@ If no C<$VERSION> was specified on the C<bootstrap> line, the last line becomes XSLoader::load 'YourPackage'; +If the call to C<load> is from the YourPackage, then that can be further +simplified to + + XSLoader::load(); + +as C<load> will use C<caller> to determine the package. + =head2 Backward compatible boilerplate If you want to have your cake and eat it too, you need a more complicated @@ -367,14 +377,8 @@ B<(W)> As the message says, some symbols stay undefined although the extension module was correctly loaded and initialised. The list of undefined symbols follows. -=item C<XSLoader::load('Your::Module', $Your::Module::VERSION)> - -B<(F)> You tried to invoke C<load()> without any argument. You must supply -a module name, and optionally its version. - =back - =head1 LIMITATIONS To reduce the overhead as much as possible, only one possible location |