do just-in-time loading of Carp.pm in some modules
authorTels <nospam-abuse@bloodgate.com>
Sat, 2 Jul 2005 16:11:46 +0000 (16:11 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Sat, 2 Jul 2005 16:11:46 +0000 (16:11 +0000)
Subject: [PATCH] No Carp #4 AutoSplit.pm
Subject: [PATCH] no Carp #5 (File::Path)
Subject: [PATCH] no Carp #7 - charnames.pm
Subject: [PATCH] no Carp #6 (File::Compare, File::Copy, File::Temp)
Subject: [PATCH] no Carp #8 - SelfLoader, Text/Balanced and open.pm

p4raw-id: //depot/perl@25052

lib/AutoSplit.pm
lib/File/Compare.pm
lib/File/Copy.pm
lib/File/Path.pm
lib/SelfLoader.pm
lib/charnames.pm
lib/open.pm

index e021e0f..bf0f925 100644 (file)
@@ -3,7 +3,6 @@ package AutoSplit;
 use 5.006_001;
 use Exporter ();
 use Config qw(%Config);
-use Carp qw(carp);
 use File::Basename ();
 use File::Path qw(mkpath);
 use File::Spec::Functions qw(curdir catfile catdir);
@@ -11,7 +10,7 @@ use strict;
 our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen,
     $CheckForAutoloader, $CheckModTime);
 
-$VERSION = "1.04";
+$VERSION = "1.04_01";
 @ISA = qw(Exporter);
 @EXPORT = qw(&autosplit &autosplit_lib_modules);
 @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
@@ -168,6 +167,10 @@ sub autosplit{
     autosplit_file($file, $autodir, $keep, $ckal, $ckmt);
 }
 
+sub carp{
+    require Carp;
+    goto &Carp::carp;
+}
 
 # This function is used during perl building/installation
 # ./miniperl -e 'use AutoSplit; autosplit_lib_modules(@ARGV)' ...
@@ -405,14 +408,14 @@ EOT
                print "  deleting $file\n" if ($Verbose>=2);
                my($deleted,$thistime);  # catch all versions on VMS
                do { $deleted += ($thistime = unlink $file) } while ($thistime);
-               carp "Unable to delete $file: $!" unless $deleted;
+               carp ("Unable to delete $file: $!") unless $deleted;
            }
            closedir($outdir);
        }
     }
 
     open(my $ts,">$al_idx_file") or
-       carp "AutoSplit: unable to create timestamp file ($al_idx_file): $!";
+       carp ("AutoSplit: unable to create timestamp file ($al_idx_file): $!");
     print $ts "# Index created by AutoSplit for $filename\n";
     print $ts "#    (file acts as timestamp)\n";
     $last_package = '';
index 0b73d7c..bcc996e 100644 (file)
@@ -6,15 +6,19 @@ use warnings;
 our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Too_Big);
 
 require Exporter;
-use Carp;
 
-$VERSION = '1.1003';
+$VERSION = '1.1004';
 @ISA = qw(Exporter);
 @EXPORT = qw(compare);
 @EXPORT_OK = qw(cmp compare_text);
 
 $Too_Big = 1024 * 1024 * 2;
 
+sub croak {
+    require Carp;
+    goto &Carp::croak;
+}
+
 sub compare {
     croak("Usage: compare( file1, file2 [, buffersize]) ")
       unless(@_ == 2 || @_ == 3);
index a43a6c6..828473e 100644 (file)
@@ -10,7 +10,6 @@ package File::Copy;
 use 5.006;
 use strict;
 use warnings;
-use Carp;
 use File::Spec;
 use Config;
 our(@ISA, @EXPORT, @EXPORT_OK, $VERSION, $Too_Big, $Syscopy_is_copy);
@@ -24,7 +23,7 @@ sub mv;
 # package has not yet been updated to work with Perl 5.004, and so it
 # would be a Bad Thing for the CPAN module to grab it and replace this
 # module.  Therefore, we set this module's version higher than 2.0.
-$VERSION = '2.08';
+$VERSION = '2.08_01';
 
 require Exporter;
 @ISA = qw(Exporter);
@@ -33,6 +32,11 @@ require Exporter;
 
 $Too_Big = 1024 * 1024 * 2;
 
+sub croak {
+    require Carp;
+    goto &Carp::croak;
+}
+
 my $macfiles;
 if ($^O eq 'MacOS') {
        $macfiles = eval { require Mac::MoreFiles };
index f96dc06..202bb48 100644 (file)
@@ -119,13 +119,12 @@ Charles Bailey <F<bailey@newman.upenn.edu>>
 =cut
 
 use 5.006;
-use Carp;
 use File::Basename ();
 use Exporter ();
 use strict;
 use warnings;
 
-our $VERSION = "1.07";
+our $VERSION = "1.07_01";
 our @ISA = qw( Exporter );
 our @EXPORT = qw( mkpath rmtree );
 
@@ -137,6 +136,16 @@ my $Is_MacOS = $^O eq 'MacOS';
 my $force_writeable = ($^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' ||
                       $^O eq 'amigaos' || $^O eq 'MacOS' || $^O eq 'epoc');
 
+sub carp {
+    require Carp;
+    goto &Carp::carp;
+}
+
+sub croak {
+    require Carp;
+    goto &Carp::croak;
+}
+
 sub mkpath {
     my($paths, $verbose, $mode) = @_;
     # $paths   -- either a path string or ref to list of paths
@@ -165,7 +174,7 @@ sub mkpath {
        unless (mkdir($path,$mode)) {
            my $e = $!;
            # allow for another process to have created it meanwhile
-           croak "mkdir $path: $e" unless -d $path;
+           croak ("mkdir $path: $e") unless -d $path;
        }
        push(@created, $path);
     }
@@ -183,7 +192,7 @@ sub rmtree {
       $roots = [$roots] unless ref $roots;
     }
     else {
-      carp "No root path(s) specified\n";
+      carp ("No root path(s) specified\n");
       return 0;
     }
 
@@ -203,7 +212,7 @@ sub rmtree {
            # to recurse in which case we are better than rm -rf for 
            # subtrees with strange permissions
            chmod($rp | 0700, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
-             or carp "Can't make directory $root read+writeable: $!"
+             or carp ("Can't make directory $root read+writeable: $!")
                unless $safe;
 
            if (opendir my $d, $root) {
@@ -217,7 +226,7 @@ sub rmtree {
                closedir $d;
            }
            else {
-               carp "Can't read $root: $!";
+               carp ("Can't read $root: $!");
                @files = ();
            }
 
@@ -237,14 +246,14 @@ sub rmtree {
                next;
            }
            chmod $rp | 0700, $root
-             or carp "Can't make directory $root writeable: $!"
+             or carp ("Can't make directory $root writeable: $!")
                if $force_writeable;
            print "rmdir $root\n" if $verbose;
            if (rmdir $root) {
                ++$count;
            }
            else {
-               carp "Can't remove directory $root: $!";
+               carp ("Can't remove directory $root: $!");
                chmod($rp, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
                    or carp("and can't restore permissions to "
                            . sprintf("0%o",$rp) . "\n");
@@ -259,13 +268,13 @@ sub rmtree {
                next;
            }
            chmod $rp | 0600, $root
-             or carp "Can't make file $root writeable: $!"
+             or carp ("Can't make file $root writeable: $!")
                if $force_writeable;
            print "unlink $root\n" if $verbose;
            # delete all versions under VMS
            for (;;) {
                unless (unlink $root) {
-                   carp "Can't unlink file $root: $!";
+                   carp ("Can't unlink file $root: $!");
                    if ($force_writeable) {
                        chmod $rp, $root
                            or carp("and can't restore permissions to "
index 40c92db..87587c3 100644 (file)
@@ -1,9 +1,8 @@
 package SelfLoader;
-# use Carp;
 require Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(AUTOLOAD);
-$VERSION = "1.0904";
+$VERSION = "1.0905";
 sub Version {$VERSION}
 $DEBUG = 0;
 
@@ -18,6 +17,7 @@ our $one_attr = qr{ (?> (?! \d) \w+ (?:$nested)? ) (?:\s*\:\s*|\s+(?!\:)) }x;
 our $attr_list = qr{ \s* : \s* (?: $one_attr )* }x;
 
 sub croak { require Carp; goto &Carp::croak }
+sub carp { require Carp; goto &Carp::carp }
 
 AUTOLOAD {
     print STDERR "SelfLoader::AUTOLOAD for $AUTOLOAD\n" if $DEBUG;
@@ -115,7 +115,7 @@ sub _load_stubs {
 sub _add_to_cache {
     my($self,$fullname,$pack,$lines, $protoype) = @_;
     return () unless $fullname;
-    (require Carp), Carp::carp("Redefining sub $fullname")
+    carp("Redefining sub $fullname")
       if exists $Cache{$fullname};
     $Cache{$fullname} = join('', "package $pack; ",@$lines);
     print STDERR "SelfLoader cached $fullname: $Cache{$fullname}" if $DEBUG;
index f895d37..b69cccc 100644 (file)
@@ -1,9 +1,8 @@
 package charnames;
 use strict;
 use warnings;
-use Carp;
 use File::Spec;
-our $VERSION = '1.04';
+our $VERSION = '1.04_1';
 
 use bytes ();          # for $bytes::hint_bits
 $charnames::hint_bits = 0x20000; # HINT_LOCALIZE_HH
@@ -44,6 +43,16 @@ my %alias3 = (
            );
 my $txt;
 
+sub croak
+{
+  require Carp; goto &Carp::croak;
+} # croak
+
+sub carp
+{
+  require Carp; goto &Carp::carp;
+} # carp
+
 sub alias (@)
 {
   @_ or return %alias3;
index 4515899..3565762 100644 (file)
@@ -1,9 +1,8 @@
 package open;
 use warnings;
-use Carp;
 $open::hint_bits = 0x20000; # HINT_LOCALIZE_HH
 
-our $VERSION = '1.04';
+our $VERSION = '1.04_01';
 
 require 5.008001; # for PerlIO::get_layers()
 
@@ -14,6 +13,10 @@ sub _get_encname {
     return;
 }
 
+sub croak {
+    require Carp; goto &Carp::croak;
+}
+
 sub _drop_oldenc {
     # If by the time we arrive here there already is at the top of the
     # perlio layer stack an encoding identical to what we would like
@@ -39,13 +42,11 @@ sub _drop_oldenc {
     require Encode;
     my ($loname, $lcname) = _get_encname($old[-2]);
     unless (defined $lcname) { # Should we trust get_layers()?
-       require Carp;
-       Carp::croak("open: Unknown encoding '$loname'");
+       croak("open: Unknown encoding '$loname'");
     }
     my ($voname, $vcname) = _get_encname($new[-1]);
     unless (defined $vcname) {
-       require Carp;
-       Carp::croak("open: Unknown encoding '$voname'");
+       croak("open: Unknown encoding '$voname'");
     }
     if ($lcname eq $vcname) {
        binmode($h, ":pop"); # utf8 is part of the encoding layer