X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FExporter.pm;h=fd95a7efef311e7fbf3afdf76916b30189f3cf5a;hb=d4fd5c69aa67ee57d4d0286857bcd78a0847cbe3;hp=de0155b54815228c84b9da2132483d43baad17ae;hpb=2b5b265092e998ff421fee7418b7d4ef196516b8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Exporter.pm b/lib/Exporter.pm index de0155b..fd95a7e 100644 --- a/lib/Exporter.pm +++ b/lib/Exporter.pm @@ -3,7 +3,7 @@ package Exporter; require 5.001; $ExportLevel = 0; -$Verbose = 0; +$Verbose = 0 unless $Verbose; require Carp; @@ -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++; @@ -125,7 +131,7 @@ sub export { } } - warn "Importing from $pkg into $callpkg: ", + warn "Importing into $callpkg from $pkg: ", join(", ",sort @imports) if $Verbose; foreach $sym (@imports) { @@ -155,7 +161,7 @@ sub import { sub _push_tags { my($pkg, $var, $syms) = @_; my $nontag; - *export_tags = *{"${pkg}::EXPORT_TAGS"}; + *export_tags = \%{"${pkg}::EXPORT_TAGS"}; push(@{"${pkg}::$var"}, map { $export_tags{$_} ? @{$export_tags{$_}} : scalar(++$nontag,$_) } (@$syms) ? @$syms : keys %export_tags); @@ -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; } @@ -254,7 +264,7 @@ try to use @EXPORT_OK in preference to @EXPORT and avoid short or common symbol names to reduce the risk of name clashes. Generally anything not exported is still accessible from outside the -module using the ModuleName::item_name (or $blessed_ref->method) +module using the ModuleName::item_name (or $blessed_ref-Emethod) syntax. By convention you can use a leading underscore on names to informally indicate that they are 'internal' and not for public use. @@ -318,7 +328,7 @@ into modules. =head2 Module Version Checking The Exporter module will convert an attempt to import a number from a -module into a call to $module_name->require_version($value). This can +module into a call to $module_name-Erequire_version($value). This can be used to validate that the version of the module being used is greater than or equal to the required version. @@ -326,9 +336,9 @@ The Exporter module supplies a default require_version method which checks the value of $VERSION in the exporting module. Since the default require_version method treats the $VERSION number as -a simple numeric value it will regard version 1.10 and being lower -than 1.9. For this reason it is strongly recommended that you use -numbers with at least two decimal places, e.g., 1.09. +a simple numeric value it will regard version 1.10 as lower than +1.9. For this reason it is strongly recommended that you use numbers +with at least two decimal places, e.g., 1.09. =head2 Managing Unknown Symbols @@ -370,7 +380,7 @@ you to easily add tagged sets of symbols to @EXPORT or @EXPORT_OK: Exporter::export_ok_tags('bar'); # add aa, cc and dd to @EXPORT_OK Any names which are not tags are added to @EXPORT or @EXPORT_OK -unchanged but will trigger a warning (with -w) to avoid misspelt tags +unchanged but will trigger a warning (with C<-w>) to avoid misspelt tags names being silently added to @EXPORT or @EXPORT_OK. Future versions may make this a fatal error.