diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2018-03-03 15:38:14 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-03-05 10:52:28 -0800 |
commit | edfb7b92a1dbd70858ea5c5356cdb6dc14ec8d3a (patch) | |
tree | bb2629f345fec7f6c66834bdb6f503d6eb243e37 /perl/Git/LoadCPAN | |
parent | perl: move CPAN loader wrappers to another namespace (diff) | |
download | tgif-edfb7b92a1dbd70858ea5c5356cdb6dc14ec8d3a.tar.xz |
perl: generalize the Git::LoadCPAN facility
Change the two wrappers that load from CPAN (local OS) or our own copy
to do so via the same codepath.
I added the Error.pm wrapper in 20d2a30f8f ("Makefile: replace
perl/Makefile.PL with simple make rules", 2017-12-10), and shortly
afterwards Matthieu Moy added a wrapper for Mail::Address in
bd869f67b9 ("send-email: add and use a local copy of Mail::Address",
2018-01-05).
His loader was simpler since Mail::Address doesn't have an "import"
method, but didn't do the same sanity checking; For example, a missing
FromCPAN directory (which OS packages are likely not to have) wouldn't
be explicitly warned about as a "BUG: ...".
Update both to use a common implementation based on the previous
Error.pm loader. Which has been amended to take the module to load as
parameter, as well as whether or not that module has an import
method.
This loader should be generic enough to handle almost all CPAN modules
out there, some use some crazy loading magic and wouldn't like being
wrapped like this, but that would be immediately obvious, and we'd
find out right away since the module wouldn't work at all.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'perl/Git/LoadCPAN')
-rw-r--r-- | perl/Git/LoadCPAN/Error.pm | 44 | ||||
-rw-r--r-- | perl/Git/LoadCPAN/Mail/Address.pm | 22 |
2 files changed, 8 insertions, 58 deletions
diff --git a/perl/Git/LoadCPAN/Error.pm b/perl/Git/LoadCPAN/Error.pm index 3513fe745b..c6d2c45d80 100644 --- a/perl/Git/LoadCPAN/Error.pm +++ b/perl/Git/LoadCPAN/Error.pm @@ -2,45 +2,9 @@ package Git::LoadCPAN::Error; use 5.008; use strict; use warnings; - -=head1 NAME - -Git::LoadCPAN::Error - Wrapper for the L<Error> module, in case it's not installed - -=head1 DESCRIPTION - -Wraps the import function for the L<Error> module. - -This module is only intended to be used for code shipping in the -C<git.git> repository. Use it for anything else at your peril! - -=cut - -sub import { - shift; - my $caller = caller; - - eval { - require Error; - 1; - } or do { - my $error = $@ || "Zombie Error"; - - my $Git_Error_pm_path = $INC{"Git/LoadCPAN/Error.pm"} || die "BUG: Should have our own path from %INC!"; - - require File::Basename; - my $Git_Error_pm_root = File::Basename::dirname($Git_Error_pm_path) || die "BUG: Can't figure out lib/Git dirname from '$Git_Error_pm_path'!"; - - require File::Spec; - my $Git_pm_FromCPAN_root = File::Spec->catdir($Git_Error_pm_root, '..', 'FromCPAN'); - die "BUG: '$Git_pm_FromCPAN_root' should be a directory!" unless -d $Git_pm_FromCPAN_root; - - local @INC = ($Git_pm_FromCPAN_root, @INC); - require Error; - }; - - unshift @_, $caller; - goto &Error::import; -} +use Git::LoadCPAN ( + module => 'Error', + import => 1, +); 1; diff --git a/perl/Git/LoadCPAN/Mail/Address.pm b/perl/Git/LoadCPAN/Mail/Address.pm index 879c2f5cd1..f70a4f064c 100644 --- a/perl/Git/LoadCPAN/Mail/Address.pm +++ b/perl/Git/LoadCPAN/Mail/Address.pm @@ -2,23 +2,9 @@ package Git::LoadCPAN::Mail::Address; use 5.008; use strict; use warnings; - -=head1 NAME - -Git::LoadCPAN::Mail::Address - Wrapper for the L<Mail::Address> module, in case it's not installed - -=head1 DESCRIPTION - -This module is only intended to be used for code shipping in the -C<git.git> repository. Use it for anything else at your peril! - -=cut - -eval { - require Mail::Address; - 1; -} or do { - require Git::FromCPAN::Mail::Address; -}; +use Git::LoadCPAN ( + module => 'Mail::Address', + import => 0, +); 1; |