Browse Source
* git://git.bogomips.org/git-svn: Move initialization of Git::SVN variables into Git::SVN. Extract Git::SVN from git-svn into its own .pm file. Prepare Git::SVN for extraction into its own file. Extract some utilities from git-svn to allow extracting Git::SVN. perl: detect new files in MakeMaker builds The Makefile.PL will now find .pm files itself. Don't lose Error.pm if $@ gets clobbered. Quiet warning if Makefile.PL is run with -w and no --localedirmaint
Junio C Hamano
13 years ago
10 changed files with 2487 additions and 2338 deletions
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
package Git::SVN::Utils; |
||||
|
||||
use strict; |
||||
use warnings; |
||||
|
||||
use base qw(Exporter); |
||||
|
||||
our @EXPORT_OK = qw(fatal can_compress); |
||||
|
||||
|
||||
=head1 NAME |
||||
|
||||
Git::SVN::Utils - utility functions used across Git::SVN |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Git::SVN::Utils qw(functions to import); |
||||
|
||||
=head1 DESCRIPTION |
||||
|
||||
This module contains functions which are useful across many different |
||||
parts of Git::SVN. Mostly it's a place to put utility functions |
||||
rather than duplicate the code or have classes grabbing at other |
||||
classes. |
||||
|
||||
=head1 FUNCTIONS |
||||
|
||||
All functions can be imported only on request. |
||||
|
||||
=head3 fatal |
||||
|
||||
fatal(@message); |
||||
|
||||
Display a message and exit with a fatal error code. |
||||
|
||||
=cut |
||||
|
||||
# Note: not certain why this is in use instead of die. Probably because |
||||
# the exit code of die is 255? Doesn't appear to be used consistently. |
||||
sub fatal (@) { print STDERR "@_\n"; exit 1 } |
||||
|
||||
|
||||
=head3 can_compress |
||||
|
||||
my $can_compress = can_compress; |
||||
|
||||
Returns true if Compress::Zlib is available, false otherwise. |
||||
|
||||
=cut |
||||
|
||||
my $can_compress; |
||||
sub can_compress { |
||||
return $can_compress if defined $can_compress; |
||||
|
||||
return $can_compress = eval { require Compress::Zlib; }; |
||||
} |
||||
|
||||
|
||||
1; |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env perl |
||||
|
||||
use strict; |
||||
use warnings; |
||||
|
||||
use Test::More tests => 2; |
||||
|
||||
require_ok 'Git::SVN::Utils'; |
||||
require_ok 'Git::SVN'; |
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/perl |
||||
|
||||
use strict; |
||||
use warnings; |
||||
|
||||
use Test::More 'no_plan'; |
||||
|
||||
use Git::SVN::Utils qw(can_compress); |
||||
|
||||
# !! is the "convert this to boolean" operator. |
||||
is !!can_compress(), !!eval { require Compress::Zlib }; |
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/perl |
||||
|
||||
use strict; |
||||
use warnings; |
||||
|
||||
use Test::More 'no_plan'; |
||||
|
||||
BEGIN { |
||||
# Override exit at BEGIN time before Git::SVN::Utils is loaded |
||||
# so it will see our local exit later. |
||||
*CORE::GLOBAL::exit = sub(;$) { |
||||
return @_ ? CORE::exit($_[0]) : CORE::exit(); |
||||
}; |
||||
} |
||||
|
||||
use Git::SVN::Utils qw(fatal); |
||||
|
||||
# fatal() |
||||
{ |
||||
# Capture the exit code and prevent exit. |
||||
my $exit_status; |
||||
no warnings 'redefine'; |
||||
local *CORE::GLOBAL::exit = sub { $exit_status = $_[0] || 0 }; |
||||
|
||||
# Trap fatal's message to STDERR |
||||
my $stderr; |
||||
close STDERR; |
||||
ok open STDERR, ">", \$stderr; |
||||
|
||||
fatal "Some", "Stuff", "Happened"; |
||||
|
||||
is $stderr, "Some Stuff Happened\n"; |
||||
is $exit_status, 1; |
||||
} |
Loading…
Reference in new issue