Extract some utilities from git-svn to allow extracting Git::SVN.
[alt-git.git] / perl / Git / SVN / Utils.pm
blob496006bc7b3b9492f2747f689a8cdda411eb5806
1 package Git::SVN::Utils;
3 use strict;
4 use warnings;
6 use base qw(Exporter);
8 our @EXPORT_OK = qw(fatal can_compress);
11 =head1 NAME
13 Git::SVN::Utils - utility functions used across Git::SVN
15 =head1 SYNOPSIS
17 use Git::SVN::Utils qw(functions to import);
19 =head1 DESCRIPTION
21 This module contains functions which are useful across many different
22 parts of Git::SVN. Mostly it's a place to put utility functions
23 rather than duplicate the code or have classes grabbing at other
24 classes.
26 =head1 FUNCTIONS
28 All functions can be imported only on request.
30 =head3 fatal
32 fatal(@message);
34 Display a message and exit with a fatal error code.
36 =cut
38 # Note: not certain why this is in use instead of die. Probably because
39 # the exit code of die is 255? Doesn't appear to be used consistently.
40 sub fatal (@) { print STDERR "@_\n"; exit 1 }
43 =head3 can_compress
45 my $can_compress = can_compress;
47 Returns true if Compress::Zlib is available, false otherwise.
49 =cut
51 my $can_compress;
52 sub can_compress {
53 return $can_compress if defined $can_compress;
55 return $can_compress = eval { require Compress::Zlib; };