This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Limit @ISA to actual DBM in AnyDBM
[perl5.git] / lib / Exporter.pm
index 72a1401..7b03732 100644 (file)
@@ -2,17 +2,21 @@ package Exporter;
 
 require 5.001;
 
+#
+# We go to a lot of trouble not to 'require Carp' at file scope,
+#  because Carp requires Exporter, and something has to give.
+#
+
 $ExportLevel = 0;
 $Verbose = 0 unless $Verbose;
 
-require Carp;
-
 sub export {
 
     # First make import warnings look like they're coming from the "use".
     local $SIG{__WARN__} = sub {
        my $text = shift;
        if ($text =~ s/ at \S*Exporter.pm line \d+.*\n//) {
+           require Carp;
            local $Carp::CarpLevel = 1; # ignore package calling us too.
            Carp::carp($text);
        }
@@ -21,6 +25,8 @@ sub export {
        }
     };
     local $SIG{__DIE__} = sub {
+       require Carp;
+       local $Carp::CarpLevel = 1;     # ignore package calling us too.
        Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
            if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
     };
@@ -107,7 +113,10 @@ sub export {
                }
            }
        }
-       Carp::croak("Can't continue after import errors") if $oops;
+       if ($oops) {
+           require Carp;
+           Carp::croak("Can't continue after import errors");
+       }
     }
     else {
        @imports = @exports;
@@ -131,7 +140,10 @@ sub export {
                warn qq["$sym" is not implemented by the $pkg module ],
                        "on this architecture";
            }
-           Carp::croak("Can't continue after import errors") if @failed;
+           if (@failed) {
+               require Carp;
+               Carp::croak("Can't continue after import errors");
+           }
        }
     }
 
@@ -149,7 +161,7 @@ sub export {
            $type eq '@' ? \@{"${pkg}::$sym"} :
            $type eq '%' ? \%{"${pkg}::$sym"} :
            $type eq '*' ?  *{"${pkg}::$sym"} :
-               Carp::croak("Can't export symbol: $type$sym");
+           do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
     }
 }
 
@@ -169,8 +181,11 @@ sub _push_tags {
     push(@{"${pkg}::$var"},
        map { $export_tags{$_} ? @{$export_tags{$_}} : scalar(++$nontag,$_) }
                (@$syms) ? @$syms : keys %export_tags);
-    # This may change to a die one day
-    Carp::carp("Some names are not tags") if $nontag and $^W;
+    if ($nontag and $^W) {
+       # This may change to a die one day
+       require Carp;
+       Carp::carp("Some names are not tags");
+    }
 }
 
 sub export_tags    { _push_tags((caller)[0], "EXPORT",    \@_) }
@@ -192,6 +207,7 @@ sub require_version {
        $version ||= "(undef)";
        my $file = $INC{"$pkg.pm"};
        $file &&= " ($file)";
+       require Carp;
        Carp::croak("$pkg $wanted required--this is only version $version$file")
     }
     $version;