@matheusbsbs / matheus-bagliano / commits / c14c8ceb13
Fork 0

Git.pm: Make File::Spec and File::Temp requirement lazy

This will ensure that the API at large is accessible to nearly all Perl versions, while only the temp file caching API is tied to the File::Temp and File::Spec modules being available. Signed-off-by: Marcus Griep <marcus@griep.us> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marcus Griep committed Aug 15, 2008 at 15:53 UTC c14c8ceb13b299892f286757e22e6af4f6cffab5
1 file changed +7 -2
perl/Git.pm
+7 -2
@@ -100,8 +100,6 @@ use Carp qw(carp croak); # but croak is bad - throw instead
100 use Error qw(:try);
101 use Cwd qw(abs_path);
102 use IPC::Open2 qw(open2);
103 -use File::Temp ();
104 -require File::Spec;
103 use Fcntl qw(SEEK_SET SEEK_CUR);
104 }
105
@@ -1009,6 +1007,8 @@ sub temp_release {
1007 sub _temp_cache {
1008 my ($name) = @_;
1009
1010 + _verify_require();
1011 +
1012 my $temp_fd = \$TEMP_FILES{$name};
1013 if (defined $$temp_fd and $$temp_fd->opened) {
1014 if ($TEMP_LOCKS{$$temp_fd}) {
@@ -1031,6 +1031,11 @@ sub _temp_cache {
1031 $$temp_fd;
1032 }
1033
1034 +sub _verify_require {
1035 + eval { require File::Temp; require File::Spec; };
1036 + $@ and throw Error::Simple($@);
1037 +}
1038 +
1039 =item temp_reset ( FILEHANDLE )
1040
1041 Truncates and resets the position of the C<FILEHANDLE>.