summaryrefslogtreecommitdiff
path: root/lib/Exporter.pm
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-06-18 09:03:00 +0000
committerCharles Bailey <bailey@genetics.upenn.edu>1996-06-18 09:03:00 +0000
commit3221d3b03bb599fb4e56ab951ff19a0d00442685 (patch)
tree5071e37148a74871892dc7ba8a43fb36d1098995 /lib/Exporter.pm
parentf6c18ff1fbcca24d301fa24a27ca9222faf9ceaa (diff)
downloadperl-3221d3b03bb599fb4e56ab951ff19a0d00442685.tar.gz
Add version check option
Diffstat (limited to 'lib/Exporter.pm')
-rw-r--r--lib/Exporter.pm16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/Exporter.pm b/lib/Exporter.pm
index 343b9fbd17..e374414505 100644
--- a/lib/Exporter.pm
+++ b/lib/Exporter.pm
@@ -91,6 +91,12 @@ sub export {
@imports = @exports;
last;
}
+ # We need a way to emulate 'use Foo ()' but still
+ # allow an easy version check: "use Foo 1.23, ''";
+ if (@imports == 2 and !$imports[1]) {
+ @imports = ();
+ last;
+ }
} elsif ($sym !~ s/^&// || !$exports{$sym}) {
warn qq["$sym" is not exported by the $pkg module];
$oops++;
@@ -176,9 +182,13 @@ sub export_fail {
sub require_version {
my($self, $wanted) = @_;
my $pkg = ref $self || $self;
- my $version = ${"${pkg}::VERSION"} || "(undef)";
- Carp::croak("$pkg $wanted required--this is only version $version")
- if $version < $wanted;
+ my $version = ${"${pkg}::VERSION"};
+ if (!$version or $version < $wanted) {
+ $version ||= "(undef)";
+ my $file = $INC{"$pkg.pm"};
+ $file &&= " ($file)";
+ Carp::croak("$pkg $wanted required--this is only version $version$file")
+ }
$version;
}