Clean-up to various pieces of Perl code we have.
* ab/perl-fixes:
perl Git::LoadCPAN: emit better errors under NO_PERL_CPAN_FALLBACKS
Makefile: add NO_PERL_CPAN_FALLBACKS knob
perl: move the perl/Git/FromCPAN tree to perl/FromCPAN
perl: generalize the Git::LoadCPAN facility
perl: move CPAN loader wrappers to another namespace
perl: update our copy of Mail::Address
perl: update our ancient copy of Error.pm
git-send-email: unconditionally use Net::{SMTP,Domain}
Git.pm: hard-depend on the File::{Temp,Spec} modules
gitweb: hard-depend on the Digest::MD5 5.8 module
Git.pm: add the "use warnings" pragma
Git.pm: remove redundant "use strict" from sub-package
perl: *.pm files should not have the executable bit
@ -32,21 +34,35 @@ $Error::THROWN = undef; # last error thrown, a workaround until die $ref works
@@ -32,21 +34,35 @@ $Error::THROWN = undef; # last error thrown, a workaround until die $ref works
# Do it this way in case there are no elements; we don't print a spurious \n
my $callstack = join( "", map { "$_\n"} @callstack );
die "\nUnhandled $etype caught at toplevel:\n\n $message\n\nThrown from: $location\n\nFull stack trace:\n\n$callstack\n";
}
sub TAXES
{
my ( $message ) = @_;
local $SIG{__WARN__} = $old_WARN if( defined $old_WARN );
$message =~ s/ at .*? line \d+\.$//;
chomp $message;
my @callstack = gen_callstack( 1 );
my $location = shift @callstack;
# $location already starts in a leading space
$message .= $location;
# Do it this way in case there are no elements; we don't print a spurious \n
my $callstack = join( "", map { "$_\n"} @callstack );
warn "$message:\n$callstack";
}
sub import
{
$old_DIE = $SIG{__DIE__};
$old_WARN = $SIG{__WARN__};
$SIG{__DIE__} = \&DEATH;
$SIG{__WARN__} = \&TAXES;
}
1;
__END__
=head1 NAME
Error - Error/exception handling in an OO-ish way
=head1 WARNING
Using the "Error" module is B<no longer recommended> due to the black-magical
nature of its syntactic sugar, which often tends to break. Its maintainers
have stopped actively writing code that uses it, and discourage people
from doing so. See the "SEE ALSO" section below for better recommendations.
=head1 SYNOPSIS
use Error qw(:try);
@ -529,7 +643,7 @@ Error - Error/exception handling in an OO-ish way
@@ -529,7 +643,7 @@ Error - Error/exception handling in an OO-ish way
try {
do_some_stuff();
die "error!" if $condition;
throw Error::Simple -text => "Oops!" if $other_condition;
throw Error::Simple "Oops!" if $other_condition;
}
catch Error::IO with {
my $E = shift;
@ -587,7 +701,7 @@ C<BLOCK> will be passed two arguments. The first will be the error
@@ -587,7 +701,7 @@ C<BLOCK> will be passed two arguments. The first will be the error
being thrown. The second is a reference to a scalar variable. If this
variable is set by the catch block then, on return from the catch
block, try will continue processing as if the catch block was never
found.
found. The error will also be available in C<$@>.
To propagate the error the catch block may call C<$err-E<gt>throw>
When evaluated C<BLOCK> will be passed one argument, which will be the
error being processed.
error being processed. The error will also be available in C<$@>.
Only one otherwise block may be specified per try block
@ -625,12 +739,25 @@ Only one finally block may be specified per try block
@@ -625,12 +739,25 @@ Only one finally block may be specified per try block
=back
=head1 COMPATIBILITY
L<Moose> exports a keyword called C<with> which clashes with Error's. This
example returns a prototype mismatch error:
package MyTest;
use warnings;
use Moose;
use Error qw(:try);
(Thanks to C<maik.hentsche@amd.com> for the report.).
=head1 CLASS INTERFACE
=head2 CONSTRUCTORS
The C<Error> object is implemented as a HASH. This HASH is initialized
with the arguments that are passed to its constructor. The elements
with the arguments that are passed to it's constructor. The elements
that are used by, or are retrievable by the C<Error> class are listed
below, other classes may add to these.
@ -655,6 +782,10 @@ an object blessed into that package as the C<-object> argument.
@@ -655,6 +782,10 @@ an object blessed into that package as the C<-object> argument.
=over 4
=item Error->new()
See the Error::Simple documentation.
=item throw ( [ ARGS ] )
Create a new C<Error> object and throw an error, which will be caught
@ -730,6 +861,13 @@ The line where the constructor of this error was called from
@@ -730,6 +861,13 @@ The line where the constructor of this error was called from
The text of the error
=item $err->associate($obj)
Associates an error with an object to allow error propagation. I.e:
$ber->encode(...) or
return Error->prior($ber)->associate($ldap);
=back
=head2 OVERLOAD METHODS
@ -759,11 +897,9 @@ to the constructor.
@@ -759,11 +897,9 @@ to the constructor.
=head1 PRE-DEFINED ERROR CLASSES
=over 4
=item Error::Simple
=head2 Error::Simple
This class can be used to hold simple error strings and values. Its
This class can be used to hold simple error strings and values. It's
constructor takes two arguments. The first is a text value, the second
is a numeric value. These values are what will be returned by the
overload methods.
@ -775,7 +911,6 @@ of the error object.
@@ -775,7 +911,6 @@ of the error object.
This class is used internally if an eval'd block die's with an error
that is a plain string. (Unless C<$Error::ObjectifyCallback> is modified)
=back
=head1 $Error::ObjectifyCallback
@ -804,6 +939,76 @@ class MyError::Bar by default:
@@ -804,6 +939,76 @@ class MyError::Bar by default:
# Error handling here.
}
=cut
=head1 MESSAGE HANDLERS
C<Error> also provides handlers to extend the output of the C<warn()> perl
function, and to handle the printing of a thrown C<Error> that is not caught
or otherwise handled. These are not installed by default, but are requested
using the C<:warndie> tag in the C<use> line.
use Error qw( :warndie );
These new error handlers are installed in C<$SIG{__WARN__}> and
C<$SIG{__DIE__}>. If these handlers are already defined when the tag is
imported, the old values are stored, and used during the new code. Thus, to
arrange for custom handling of warnings and errors, you will need to perform
something like the following:
BEGIN {
$SIG{__WARN__} = sub {
print STDERR "My special warning handler: $_[0]"
};
}
use Error qw( :warndie );
Note that setting C<$SIG{__WARN__}> after the C<:warndie> tag has been
imported will overwrite the handler that C<Error> provides. If this cannot be
avoided, then the tag can be explicitly C<import>ed later
use Error;
$SIG{__WARN__} = ...;
import Error qw( :warndie );
=head2 EXAMPLE
The C<__DIE__> handler turns messages such as
Can't call method "foo" on an undefined value at examples/warndie.pl line 16.
into
Unhandled perl error caught at toplevel:
Can't call method "foo" on an undefined value
Thrown from: examples/warndie.pl:16
Full stack trace:
main::inner('undef') called at examples/warndie.pl line 20
main::outer('undef') called at examples/warndie.pl line 23
=cut
=head1 SEE ALSO
See L<Exception::Class> for a different module providing Object-Oriented
exception handling, along with a convenient syntax for declaring hierarchies
for them. It doesn't provide Error's syntactic sugar of C<try { ... }>,
C<catch { ... }>, etc. which may be a good thing or a bad thing based
on what you want. (Because Error's syntactic sugar tends to break.)
L<Error::Exception> aims to combine L<Error> and L<Exception::Class>
"with correct stringification".
L<TryCatch> and L<Try::Tiny> are similar in concept to Error.pm only providing
a syntax that hopefully breaks less.
=head1 KNOWN BUGS
None, but that does not mean there are not any.
@ -816,12 +1021,20 @@ The code that inspired me to write this was originally written by
@@ -816,12 +1021,20 @@ The code that inspired me to write this was originally written by
Peter Seibel <peter@weblogic.com> and adapted by Jesse Glick
<jglick@sig.bsh.com>.
C<:warndie> handlers added by Paul Evans <leonerd@leonerd.org.uk>
=head1 MAINTAINER
Shlomi Fish <shlomif@iglu.org.il>
Shlomi Fish, L<http://www.shlomifish.org/> .
=head1 PAST MAINTAINERS
Arun Kumar U <u_arunkumar@yahoo.com>
=head1 COPYRIGHT
Copyright (c) 1997-8 Graham Barr. All rights reserved.
This program is free software; you can redistribute it and/or modify it
BUG: The '%s' module is not here, but NO_PERL_CPAN_FALLBACKS was set!
Git needs this Perl module from the CPAN, and will by default ship
with a copy of it. This Git was built with NO_PERL_CPAN_FALLBACKS,
meaning that whoever built it promised to provide this module.
You're seeing this error because they broke that promise, and we can't
load our fallback version, since we were asked not to install it.
If you're seeing this error and didn't package Git yourself the
package you're using is broken, or your system is broken. This error
won't appear if Git is built without NO_PERL_CPAN_FALLBACKS (instead
we'll use our fallback version of the module).
THEY_PROMISED
die $error;
}
my $Git_LoadCPAN_pm_path = $INC{"Git/LoadCPAN.pm"} || die "BUG: Should have our own path from %INC!";
require File::Basename;
my $Git_LoadCPAN_pm_root = File::Basename::dirname($Git_LoadCPAN_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_LoadCPAN_pm_path'!";
require File::Spec;
my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_LoadCPAN_pm_root, '..', 'FromCPAN');
die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root;