Skip to content

Commit

Permalink
Git.pm: Make File::Spec and File::Temp requirement lazy
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Marcus Griep authored and Junio C Hamano committed Aug 16, 2008
1 parent 4370c2d commit c14c8ce
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions perl/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ use Carp qw(carp croak); # but croak is bad - throw instead
use Error qw(:try);
use Cwd qw(abs_path);
use IPC::Open2 qw(open2);
use File::Temp ();
require File::Spec;
use Fcntl qw(SEEK_SET SEEK_CUR);
}

Expand Down Expand Up @@ -1009,6 +1007,8 @@ sub temp_release {
sub _temp_cache {
my ($name) = @_;

_verify_require();

my $temp_fd = \$TEMP_FILES{$name};
if (defined $$temp_fd and $$temp_fd->opened) {
if ($TEMP_LOCKS{$$temp_fd}) {
Expand All @@ -1031,6 +1031,11 @@ sub _temp_cache {
$$temp_fd;
}

sub _verify_require {
eval { require File::Temp; require File::Spec; };
$@ and throw Error::Simple($@);
}

=item temp_reset ( FILEHANDLE )
Truncates and resets the position of the C<FILEHANDLE>.
Expand Down

0 comments on commit c14c8ce

Please sign in to comment.